Results 1 to 2 of 2
Good afternoon!
I had a question regarding the ternary operator. Does one exist for BASH? I know for Perl it exists.
The code I'm trying to execute is:
echo -n ...
- 11-03-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 7
BASH Ternary Operator?
Good afternoon!
I had a question regarding the ternary operator. Does one exist for BASH? I know for Perl it exists.
The code I'm trying to execute is:
echo -n "Enter your name: "
read NAME
if [ -z "$NAME" ] ; then
echo "You did NOT enter your name!"
else
echo "Hello $NAME"
fi
(So basically, if the user enters a name, it says "Hello User!" else it tells them they did not enter their name). How would I simplify something like that into a ternary operator. Examples I've looked at on the web have not worked.
Thanks
Shamshir
- 11-06-2010 #2Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 262
Code:read -p "Enter your name: " NAME [ -z "${NAME}" ] && echo You did NOT enter your name!" || echo "Hello ${NAME}"


Reply With Quote