[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

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
> #!/bin/sh
> rm -f highs
> for line in $(cat temp.csv)
> do
> high52=$(echo $line|cut -d, -f4)
> high=$(echo $line|cut -d, -f2)
> stock=$(echo $line|cut -d, -f1)
> if [[ $high52 = $high ]]
> then
> echo $stock >> highs
> fi
> done
> 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.

Good luck!


> lvgandhi@lvgvaio:~$ head -n5 temp.csv
> ABB,4368.10,4211.65,4368.10,1900.00
> ACC,894.00,870.00,1194.80,601.00
> BAJAJAUTO,2250.00,2170.00,3375.20,2074.10
> BHARTIARTL,863.40,842.00,882.05,307.30
> --
> L.V.Gandhi
> http://lvgandhi.tripod.com/
> linux user No.205042

Ken Irving

Reply to: