First of all, just to be certain, we are talking about shell scripting here?
This is backwards. You can't set a numbered parameter inside the script, and you don't prefix a variable with $ when setting it. I believe you want
file=$1 instead.
Code:
case
var=(a;; b;; c;; d;;)
esac
This is not a correct case syntax. A case statement is a kind of testing construct. It needs an input value to test, a list of conditions to test it against, and a set of operations to perform.
Code:
case $1 in
a) echo "this is value a" ;;
b) echo "this is value b" ;;
c) echo "this is value c" ;;
esac
As it stands the part inside the case/esac would actually be treated as an array setting step instead, if the rest of it didn't error out. Could you please explain in detail what you are really trying to do here?
Code:
for i in $file
grep ^1 $i | awk '{ if ($4==$var) {print $0} }'
done
The correct syntax for a for loop is:
Code:
for var in <list>; do
commands using "$var"
done
Note that you forgot the "do" keyword.
Also,
QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes
awk cannot generally use shell variables directly. You have to import them into
awk variables using the
-v option.
Finally, there's the
Useless Use Of Grep, but that's a minor problem compared to the rest.
Here are a few useful bash scripting references:
http://mywiki.wooledge.org/BashGuide
http://wiki.bash-hackers.org/start
http://www.linuxcommand.org/index.php
http://wiki.bash-hackers.org/scripting/newbie_traps
http://mywiki.wooledge.org/BashPitfalls
http://mywiki.wooledge.org/BashFAQ
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/index.html
http://www.gnu.org/software/bash/manual/bashref.html
http://ss64.com/bash/
I suggest reading through the first one carefully, at least.
Here are a few useful awk references:
http://www.grymoire.com/Unix/Awk.html
http://www.gnu.org/software/gawk/man...ode/index.html
http://www.pement.org/awk/awk1line.txt
http://www.catonmat.net/blog/awk-one...ined-part-one/