Reputation: 11
i am new to scripting.how do i correct this bash script. for all values it gives me the "else" condition - "wrong value"
#!/bin/bash
read -p "First Name: " $first
read -p "Last Name: " $last
read -p "profession 1 for software and 2 for hardware (1/2): " $pro
echo $first
if [ "$pro" == "1" ];then
echo $first
echo $last
elif [ "$pro" == "2" ];then
echo $first
echo $last
echo $pro
else
echo "wrong value!"
fi
Upvotes: 0
Views: 32
Reputation: 10460
You need to change …
read -p "First Name: " $first
read -p "Last Name: " $last
read -p "profession 1 for software and 2 for hardware (1/2): " $pro
… to …
read -p "First Name: " first
read -p "Last Name: " last
read -p "profession 1 for software and 2 for hardware (1/2): " pro
Note the lack of $
on first
, last
and pro
. In shell you do not use the $
on a variable when assigning it a value.
Upvotes: 1