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

Re: bash help please



On Thu 09 Jun 2016 at 22:41:27 (-0400), Gene Heskett wrote:
> A bash script that has worked most of a decade now refuses.
> 
> For instance, assume that var InMail is = "gene", and can be echoed from 
> the command line using $InMail like this.
> gene@coyote:~$ echo $InMail
> gene
> But I'll be switched if I can get a result from a line of code resembling 
> this from the command line while attempting to troubleshoot a 110 line 
> bash script: which asks "if test [${InMail} = "gene"]
> 			  then
> 				-----
> 			 elif (another name)
> 				yadda yadda
> 
> gene@coyote:~$ echo `test [${InMail} = "gene"]`
> 
> All I get is the linefeed.  Obviously I'm losing it, so how do I 
> translate and get usefull output for troubleshooting?

$ `[ ${InMail} = "gene" ]` ; echo $?
0
$ `[ ${InMail} = "xgene" ]` ; echo $?
1
$ `test ${InMail} = "gene"` ; echo $?
0
$ `test ${InMail} = "xgene"` ; echo $?
1
$ 

elif needs [], not (), and it needs a then too.

[ is a command like test, so it must be followed by a space
before its argument.

Often the easiest way of solving these is grep -A ... used with
/etc/init.d/*

Cheers,
David.


Reply to: