Hi
I wrote a script which lists the content of a given directory.
I have just one problem. If you give 2 or more parameters, then it gives a strange error. After that error, it gives also an error from my script, but normally it shouldn't give that error.
Here's my script.You can test it.
#!/bin/bash
EDITOR=vim
PASSWD=/etc/passwd
RED='\033[0;41;30m'
STD='\033[0;0;39m'
pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}
one(){
echo "Give in a directory name:"
read name
if [ ! $# -gt 0 ]; then
if [ -d $name ]; then
echo "Ok. Here's the content of the given directory:"
echo
ls -l -- $name
exit 0
else
echo "Directory name doesn't exist or isn't a directory."
exit 1
fi
else
echo "No or more than one param."
exit 2
fi
pause
}
show_menus() {
clear
echo "~~~~~~~~~~~~~~~~~~~~~"
echo " MAIN - MENU "
echo "~~~~~~~~~~~~~~~~~~~~~"
echo "1. List content of a directory by given param"
echo "2. Exit"
}
# read input from the keyboard and take a action
# invoke the one() when the user select 1 from the menu option.
# Exit when user the user select 2 form the menu option.
read_options(){
local choice
read -p "Enter choice [ 1 - 2] " choice
case $choice in
1) one ;;
2) exit 0;;
*) echo -e "${RED}Error...${STD}" && sleep 1
esac
}
# ----------------------------------------------
# Ignore CTRL+C, CTRL+Z and quit singles
# ----------------------------------------------
trap '' SIGINT SIGQUIT SIGTSTP
# -----------------------------------
# List menu while true
# ------------------------------------
while true
do
clear
show_menus
read_options
done