Bash script if elif problem
Hi,
I have the following code for a bash script when i send -f to the script is displays -f as expected however any other arguments i sent e.g. -u or -v, it goes straight to the else branch e.g ./script.sh -u results in no matches with parameter -u Am I doing something wrong here? I have also tried putting the first if and then on the same line with a semi-colon after the brace i.e. if [ "$1" == "$FILE" ]; then echo "-f" and leaving the rest unchanged but this still produces the same problem Thanks |
elif [ "$1" == "UDP" ]
should be: elif [ "$1" == "$UDP" ] elif [ "$1" == "V4L" ] should be: elif [ "$1" == "$V4L" ] ---------------------- Steve Stites |
#!/bin/bash
FILE="-f" UDP="-u" V4L="-v" if [ "$1" == "$FILE" ] then echo "-f" elif [ "$1" == "UDP" ] -->$UPD then echo "-u" elif [ "$1" == "V4L" ] -->$V4L then echo "-v" else echo "no matches with parameter $1" fi run your script in debug mode.. sh -x your_script_name.sh and see what you want to compare and what it is actually comparing.. Cheers!! |
All times are GMT -5. The time now is 03:05 AM. |