2017-05-30 14 views
0

ここに新しいユーザーがいます。私が正しく投稿していないと申し訳ありませんが、このコードを何時間も見つめていて、何が間違っているかを知ることができません。それは非常によく似ていて、うまくいけば、私が間違っていることを教えてください。bashスクリプトが動作しない、何もエラーが発生しない

#!/bin/bash 

export TERM=xterm 
while true 
do 
    clear #Gets rid of previous output 
    #displays main menu 
    menu="Main menu: 
    showMan = Show the manual path. 
    addMan = Add an item to the manual path. 
    setMan = Set the manual path to '/man'. 
    fileName = Enter filename. 
    editFile = Edit file. 
    headDisplay = How many lines to display of the head of the file? 
    tailDisplay = How many lines to display of the tail of the file? 
    listProcess = listing of processes 
    userProcess = Processes run by user 
    quit = Exit" 
    echo -e "$menu"; 
    read -r option 
    #gets user choice 
    clear 
    case $option in 
    "showMan") 
     echo $MANPATH 
     ;; 

    "addMan") 
     echo "Add an item" 
     read -r item 
     export MANPATH="$MANPATH:$item" 
     ;; 

    "setMan") 
     export MANPATH="/man" 
     ;; 

    "fileName") 
     echo "Enter filename:" 
     read -r filename 
     ;; 

    "editFile") 
     nano "$filename" 
     ;; 

    "headDisplay") 
     echo "How many lines of code to display from top of the file?:" 
     read -r numLines 
     head -"$numLines" "$filename" 
     ;; 

    "tailDisplay") 
     echo "How many lines of code to display from bottom of the file?:" 
     read -r numLines 
     tail -"$numLines" "$filename" 
     ;; 

    "listProcess") 
     ps -ef 
     ;; 

    "userProcess") 
     echo "Please enter username:" 
     read -r username 
     ps -u "$username" | sed 1d | wc -l 
     ;; 

    "quit") 
     exit 
     ;; 

    *) 
     echo "Invalid input." 
     ;; 
    esac 

    #Asks user if they want to continue 
    echo "Would you like to continue? (Y/n)" 
    read -r input 
    if [ "$input" == "n" ]; then 
     exit 
    fi 
done 
+3

エラーは何ですか? –

+0

私はLinuxのターミナルを介して.shファイルとして実行していますが、実際には "悪いインタプリタ:そのようなファイルや辞書はありません"というメッセージが表示されます。 –

+0

私はLinux端末で動作する他の.SHファイルを使用しています。 –

答えて

0

あなたの問題は、スクリプトの先頭に彼女-強打です:

#!/bin/bash

これは、スクリプトを実行するために、このインタプリタ/シェルを使用して、あなたの現在のシェルに指示します。あなたの場合、実行可能ファイルは/bin/bashにありません。

問題を修正するには、bashシェル実行ファイルの場所に変更するか( "which bash"で見つけることができます)、または現在のシェルを使用するために削除してください。

スクリプト内でbash固有のコマンドとステートメントを使用すると、デフォルトとは異なるシェルを使用している場合に破損する可能性があるため、パスフィックスを優先します。

+0

タンクして!それは今でも別のエラーを投げています:source_file.sh:行23:予期しないトークン '$ 'in \ r' 'の構文エラー source_file.sh:行23:' \t case $ option in' –

+0

コピーしました。あなたの投稿のスクリプトを_vim_に貼り付けてください。 WindowsのUbuntuシェルと完全に連携しました。さらにエンコードの問題かもしれません。行を削除したのか、それとも正しいパスで修正しましたか? –

+0

私はラインを削除しましたが、私はサイラスのアドバイスを受け取り、修正しました。 –

関連する問題