Help with first bash script please

Paul Howarth paul at city-fan.org
Thu Oct 21 15:16:07 UTC 2004


Graham Cossey wrote:
> I'm going nowhere at the moment with this VERY simple bash script, can
> someone help please?
> 
> All I need to do is check the value of one of the command line parameters
> and conditionally perform a task
> 
> 1 #!/bin/bash
> 2 printf "Type = $6"
> 3 if [$6 == 'F']
> 4 then
> 5    Do the task
> 6 fi
> 7 Do other tasks
> 
> I keep getting:
> 
> Type = Q
> line 3: [Q: Command not found

Add a space between the "[" and the "$6"; since "$6" is "Q", without the space 
you're trying to run a command "[Q", which doesn't exist. Also it's a good 
idea to put double quotes around parameters in case the parameter turns out to 
be empty (non-existent):

#!/bin/bash
echo "Type = $6"
if [ "$6" == 'F' ]; then
	Do the task
fi
Do other tasks

> Also, does someone have a 'simple' bash scripting resource they could point
> me to? I can find plenty of advanced scripting pages but founf nothing with
> the above example that worked.

Try http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

Paul.




More information about the fedora-list mailing list