This is the bash script I am writing. You can see the expected output. But I am getting something else. Where could I be making a mistake?
#!/bin/bash
#Demostrate how read actually works
echo What cars do you like?
read car1 car2 car3
echo Your first car was: $car1
echo Your second car was: $car2
echo Your third car was: $car3
Expected output
./cars.sh
What cars do you like?
Jaguar Maserati Bentley Lotus
Your first car was: Jaguar
Your second car was: Maserati
Your third car was: Bentley Lotus
Actual Output
[root@localhost ~]# ./cars.sh
What cars do you like?
Jaguar
Your first car was: Jaguar
Your second car was:
Your third car was:
[root@localhost ~]#
read
command. If you input too many words, the extra collects in the last variable (thuscar3
is "Bentley Lotus" in your first example). If you don't input enough words, it leaves the later variables empty (thus,car2
andcar3
are blank in your second example).