I'm just getting started on a script that does basic shell commands, but the second function, which is supposed to take a valid year and month and plug them into cal, is returning with this error:
Enter the year:
2014
/home/duncan/menuscript.sh: line 34: [2014: command not found
/home/duncan/menuscript.sh: line 34: [2014: command not found
This is an invalid year
This is the code I am working on, I have looked for the answer already, and I cant figure out why it wont compile.. I am not trying to enter the date as a command!
#!/bin/bash
echo "Welcome to Duncan's main menu"
function press_enter
{
echo ""
echo -n "Press Enter to continue"
read
clear
}
year=
month=
selection=
until [ "$selection" = "9" ]
do
clear
echo ""
echo " 1 -- Display users currently logged in"
echo " 2 -- Display a calendar for a specific month and year"
echo " 3 -- Display the current directory path"
echo " 4 -- Change directory"
echo " 5 -- Long listing of visible files in the current directory"
echo " 6 -- Display current time and date and calendar"
echo " 7 -- Start the vi editor"
echo " 8 -- Email a file to a user"
echo " 9 -- Quit"
echo ""
echo "Make your selection:"
read selection
echo ""
case $selection in
1) who ; press_enter ;;
2) echo "Enter the year:" ;
read year ;
if [$year>1] || [$year<9999]; then
echo "Enter the month:"
read month
if [0<$month<12]; then
cal -d $year-$month
press_enter
else
echo "This is an invalid month"
press_enter
fi
else
echo "This is an invalid year"
press_enter
fi ;;
9) exit ;;
*) echo "Please enter a valid option" ; press_enter ;;
esac
done
#!/bin/bashanyway, why not useselectrather thancasehere? It does pretty much all of that automatically, I think. Though, if I recall correctly - (not guarantee),bashcan sometimes trip up*)rather than(*).... Oh yeah, the issue is probably here:if [0<$month<12]- you want some spaces and quotes I think...