bash 脚本不工作,无法发现任何错误
bash script not working, cant spot any errors
这里是新用户,对不起,如果我没有正确发布,但我已经盯着这段代码看了好几个小时了,我找不到它有什么问题,我之前写了一些代码非常相似并且有效好的,请让我知道我做错了什么。
#!/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
你的问题是脚本开头的 she-bang:
#!/bin/bash
这会指示您当前的 shell 使用此 interpreter/shell 来执行脚本。在您的情况下,它在 /bin/bash.
找不到可执行文件
要解决此问题,您应该将其更改为 bash shell 可执行文件的位置(您可以使用 "which bash" 找到它)或删除它以使用当前 shell.
我更喜欢路径修复,因为如果您在脚本中使用 bash 特定命令和语句,如果您使用不同的 shell 作为默认值,它将中断。
这里是新用户,对不起,如果我没有正确发布,但我已经盯着这段代码看了好几个小时了,我找不到它有什么问题,我之前写了一些代码非常相似并且有效好的,请让我知道我做错了什么。
#!/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
你的问题是脚本开头的 she-bang:
#!/bin/bash
这会指示您当前的 shell 使用此 interpreter/shell 来执行脚本。在您的情况下,它在 /bin/bash.
找不到可执行文件要解决此问题,您应该将其更改为 bash shell 可执行文件的位置(您可以使用 "which bash" 找到它)或删除它以使用当前 shell.
我更喜欢路径修复,因为如果您在脚本中使用 bash 特定命令和语句,如果您使用不同的 shell 作为默认值,它将中断。