Re: bash help please
On Friday 10 June 2016 00:00:12 David Christensen wrote:
> On 06/09/2016 07:41 PM, 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?
>
> 'test' and '[ ... ]' are very similar. I use the latter. I
> definitely don't use both in one line.
>
>
> When comparing variables against string constants in '[ ... ]'
> expressions, I put quotes around the variables.
>
>
> Here's a short script that seems to work correctly:
>
> 2016-06-09 20:48:40 dpchrist@t7400 ~/sandbox/bash
> $ cat gene-heskett.sh
> #!/bin/bash
> export InMail="gene"
> echo "InMail=${InMail}"
> if [ "${InMail}" = "gene" ]
> then
> echo "InMail is gene"
> elif [ "$InMail" = "david" ]
> then
> echo "InMail is david"
> else
> echo "InMail unknown"
> fi
>
>
> Here's a run:
>
> 2016-06-09 20:49:30 dpchrist@t7400 ~/sandbox/bash
> $ ./gene-heskett.sh
> InMail=gene
> InMail is gene
>
>
> Here's a run with the '-x' option:
>
> 2016-06-09 20:56:19 dpchrist@t7400 ~/sandbox/bash
> $ bash -x gene-heskett.sh
> + export InMail=gene
> + InMail=gene
> + echo InMail=gene
> InMail=gene
> + '[' gene = gene ']'
> + echo 'InMail is gene'
> InMail is gene
>
>
> If that doesn't help, post a complete script that demonstrates the
> problem.
>
>
> David
I might just take you up on that when I am ready to add another layer of
bulletproofing to it. Its about 110 lines now.
Cheers, Gene Heskett
--
"There are four boxes to be used in defense of liberty:
soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
Genes Web page <http://geneslinuxbox.net:6309/gene>
Reply to: