The Script(input.sh):
echo "What is your name?"
if [[ $1 =~ "*" ]]
then
read name1
read name2
echo "Are you really "$name1 "??? or" $name2 "?"
else
echo "Are you really "$1 "??? or" $2 "?"
fi
What I want is if I run the command:./input.sh fahad Eclipse
Then it should print:
What is your name?
Are you really fahad ??? or Eclipse ?
Also, if I do this: ./input.sh
Then it should ask me for input and then print the line.
How can I do that ?
Your script isn't executing properly due to your if statement, the following should work. It requires 2 args, or it will ask them name1 and name2.
The if statement contains '$#' which calculates the number of arguments given. The follow '-ne' is the comparison operator for 'not equal to'. Finally the last number is for how many you're expecting. So in our case, we're looking for exactly 2, if 1, or 4 are given, the else statement will be executed.