echo "Enter the variable: " "
read var1
echo " "
for i in ib eb atm
do
if [ $var1 = $i ]; then
mv properties environment.properties
break
else
echo "No changes to $var1 "
fi
done
When i run and enter the eb it's not working.Any suggestions please..
1)I am using AIX operating system.
2) I am using bash shell
3)Entered value is ib or eb or atm then it should mv properties environment.properties else it should not exit from the script. It should move next step in the script.
I didn't see any error messages but my logic is not working. When I compare if [ $var1 = $i ]
Var1= eb it should mv the file but it is going else place.
echo "Enter the variable: "
read var1
echo " "
for i in ib eb atm
do
if [[ $var1 == $i ]]; then
mv properties environment.properties
break
else
echo "No changes to $var1 "
fi
done
first, test s string comparison operator is not "=" but "==", as SriniShoo has already stated;
second, you should quote your variables: if "$var" contains whitespace, your command is going to fail with a syntax error otherwise:
if [ "$var1" == "$i" ]; then
In addition your logic is flawed: the for-loop will try one possible value after the next and for every failed attempt print "no changes". Hence, if you enter "atm" the output will read something like:
No changes to atm
No changes to atm
and your file will get moved - or not, depending on it being there in first place, otherwise you will get an error.
You might want to make the output of your script somewhat better understandable.