Read contents of file and execute command
I have a file named PKGSEL with on line like this:
"Var1" "Var2" "Var3" "Var4" I don't know how to do something like this: if PKGSEL file contains "Var1" then the script should execute a command, if it contains "Var2" is should execute another command - and so on... |
VAR=`cat PKGSEL`
if [ "$VAR" = "Var1" ]; |
VAR=`cat PKGSEL`
if [ "$VAR" = "Var1" ]; then command1 elif [ "$VAR" = "Var2" ]; then command2 elif [ "$VAR" = "Var3" ]; then command3 fi |
If there's more than one "Var" on the line in the file this will work, also if the quotes are actually in the file this handles it:
do_cmd() ( if [ "$1" = "Var1" ]; then echo command1 elif [ "$1" = "Var2" ]; then echo command2 elif [ "$1" = "Var3" ]; then echo command3 fi ) list_vars() { pcount=$# i=1 while [ $i -le $pcount ]; do do_cmd $1 shift (( i = i + 1 )) done } list_vars `cat PKGSEL | sed 's/"//g'` |
All times are GMT -5. The time now is 08:21 PM. |