If .. then... else .. fi
I am trying to learn if , then , else statements and I can't get it correct. I have written a basic script below and from what I am reading it looks correct but it does not go to the second option (else) if the first argument is not true.
Any help would be appreciated.:newbie: Quote:
PS -> This is not homework question. (Kinda sounds like one) Not even in school. Just trying to learn...:study: |
if [ $answer = yes ]
You need the spaces to make a valid comparison. Note: you may want to use == instead of =. It helps to avoid that sort of confusion. |
Thanks !!!
:hattip:
white space = Root of all evil :doh: Thanks for the help. |
Please mark as SOLVED if you have a solution.
|
Even better in bash and ksh you might use the extended test command, with double square brackets. Among other advantages, it prevents logic errors when the value of the variable is null and you missed the double quotes around it. Example:
Code:
if [[ $answer == yes ]] |
Quote:
|
No doubt. But even the "echo" command is not as portable as many seem to assume; for maximum portability C-like printf should be used...
|
All times are GMT -5. The time now is 05:07 PM. |