#!/bin/bash
until ["$userIn" = "j"]
do
echo "Welcome to the Menu_Script Program!"
echo
echo "Menu Options"
echo "Please Select an Option."
echo
echo
echo "Press a to use the Emailer Program"
echo
echo "Press b to Display the Users that are Currently Logged On"
echo
echo "Press c to Display the Current Date and Time"
echo
echo "Press d to Display the Months Calendar"
echo
echo "Press e to Display the name of the Working Directory"
echo
echo "Press f to Display the Contents of the Working Directory"
echo
echo "Press g to Find the IP of a Web Address"
echo
echo "Press h to See your Fortune"
echo
echo "Press i to Display a file on the screen"
echo
echo
echo "Press j to Exit this Menu"
echo
echo "Press m to show the Menu Options again"
echo
read mOption
case "$mOption" in
a|A)
echo "Welcome to the Emailer Program"
echo
echo "Please enter the content of your message and press <ENTER>:"
read $mContent
echo
echo "Please enter the email address of the recipient and press <ENTER>:"
read $mAddress
echo
echo "Is there a file to be attached to this message? Press Y/N:"
read $ATTACH
echo
if ["$ATTACH"="Y"|"y"]
then
echo "Please enter the name of the FILE to be attached:"
read $mAttach
mail -s "$mContent" "$mAddress"<"$mAttach"
echo
echo "Your mail will be sent with the attachment."
echo
else
mail -s "$mContent""$mAddress"
echo
echo "Your mail will be sent without an attachment."
echo
fi
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
b|B)
echo "Here is a list of users that are currently logged on:"
w
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
c|B)
echo "The current date and time:"
date
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
d|D)
echo "Here is the current Months of the calendar:"
cal
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
e|E)
echo "Here is the name of the Working Directory:"
pwd
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
f|F)
echo "Here is the Contents of the Working Directory"
ls
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
g|G)
echo "Please type a Web Address whose IP Address you"
echo "would like to find, then press <ENTER>:"
read $mWeb
echo
echo "Here is the IP Address Information:"
nslookup $mWeb
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
h|H)
echo "Here is your Fortune for today!"
echo
fortune
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
i|I)
echo "Please enter the name of the file that you want to be displayed:"
read $mFile
echo
echo "Here is your file:"
cat $mFile
echo
echo "Select a new Option, press j to Exit or m to show the Menu Options:"
echo
;;
j|J)
echo "Thank you for using the Menu_Script Program!"
userIn = j
echo
;;
m|M)
echo "Menu Options"
echo "Please Select an Option:"
echo
echo
echo "Press a to use the Emailer Program"
echo
echo "Press b to Display the Users that are Currently Logged On"
echo
echo "Press c to Display the Current Date and Time"
echo
echo "Press d to Display the Months Calendar"
echo
echo "Press e to Display the name of the Working Directory"
echo
echo "Press f to Display the Contents of the Working Directory"
echo
echo "Press g to Find the IP of a Web Address"
echo
echo "Press h to See your Fortune"
echo
echo "Press i to Display a file on the screen"
echo
echo
echo "Press j to Exit this Menu"
echo
echo "Press m to show the Menu Options again"
echo
;;
*)
echo "Invalid Selection."
echo "Select a valid option, press j to Exit or m to show the Menu Options"
;;
esac
done
答案1
[
是一个命令。
因此,您必须像任何其他命令一样在其后面添加空格来处理参数。
尝试man [
。
如果您echofoo
在终端中输入,它将无法工作,除非您有一个明确名为 的二进制/命令echofoo
,它很可能会说与您的错误相同的内容echofoo: command not found.
答案2
您需要在左括号后添加空格符号,在右括号前添加空格。这行:
if ["$ATTACH"="Y"|"y"]
成为(使用多个符号)
if [[ $ATTACH == [Yy] ]]
同样对于
until ["$userIn" = "j"]
成为
until [ "$userIn" = "j" ]