Re: bash script error
On Tue, May 22, 2007 at 01:55:40PM -0700, L.V.Gandhi wrote:
> The following script works.
> for line in $(cat temp.csv);do high52=$(echo $line|cut -d, -f4);high=$(echo $line|cut -d, -f2);if
> [[ $high52 = $high ]]; then stock=$(echo $line|cut -d, -f1); echo $stock >> highs;fi;done
> But when it is put in a script file, than command line as
> rm -f highs
> for line in $(cat temp.csv)
> high52=$(echo $line|cut -d, -f4)
> high=$(echo $line|cut -d, -f2)
> stock=$(echo $line|cut -d, -f1)
> if [[ $high52 = $high ]]
> echo $stock >> highs
> I get error as
> /home/lvgandhi/bin/gethilo: 12: [[: not found
> Any suggestions please?
My suggestion is to use whitespace, i.e., indentation and blank lines,
to clarify what parts of your post are questions, code, background
information, data, etc.. With it all run together I'd need to copy and
reformat to make any sense of it. I started to do that, but didn't get
I'm all for bash scripting, but it can get pretty obtuse. When I get
that sort of error it's back to the manpage, try some different forms,
just mess with it generally until it works.
For the particular error, create a much simplified script with only
the [[ ... ]] construct, and then see what's needed to make it work.
It's probably something simple -- maybe escape the newline after 'then'?
Perl, python, ruby, awk, tcl, etc., etc., are all available and in many
cases can be clearer and easier to use when it comes to scripting.
> lvgandhi@lvgvaio:~$ head -n5 temp.csv
> linux user No.205042