Shell scripting yes/no case?
Ok, so I am shell scripting retarded and I'm sure then is an easy question to answer.
I have to write a shell script that you must enter two command line arguments. If you enter in two arguments, then it asks if you have a typo, answering Yy or Nn. If no, it goes on to ask if it is a directory etc. Do I use the case argument for the Yy or Nn? How do I get the shell to continue with the next test if I do use case? Here is my shell script so far.... if test $# -ne 2 then echo You must enter exactly 2 command line arguments, please try again. exit 1 fi if test $# -eq 2 then echo The command line arguments that you entered are $1 and $2. Did you make a typo when entering the commands? Y or N. read choice case "$choice" in Y|y) echo Program exiting because you said you had a typo. Please try again.;; N|n) if test ! -f $1 && $2 then echo Both files not located, please try again. etc etc is this correct or do I use another test like test "$choice" = Y|y?? I'm confused.. my linux prof doesn't like to explain anything.. |
I would use
read choice case "$choice" in Y|y) echo Program exiting because you said you had a typo. Please try again. exit 1 ;; N|n) ;; *) echo You must enter Y or N ;; esac |
All times are GMT -5. The time now is 03:06 PM. |