Re: bash scripts conditionals and substrings

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kevin Brown
Date:  
To: plug-discuss
Subject: Re: bash scripts conditionals and substrings
Craig White wrote:

> On Mon, 2005-02-28 at 22:58 -0700, Kevin wrote:
>
>>On Mon, 2005-02-28 at 22:43 -0700, Craig White wrote:
>>
>>>I now have in my tried and failed...
>>>
>>>#    if [ "START" == ${i:5:5} ]
>>>#    if [ `echo $i | awk '{print substr($i,5,5)}'` = "START" ]
>>>#    if [ `expr substr $i 5 5` == "START" ]

>>
>>As a test, try echoing ${$i:5:5} directly inside the 'do' structure
>>without any "if" conditionals. Make sure it shows what you expect
>>("START").
>
> ---
> actually I have and had confusing results but I did even better than
> that
>
> I did...
>
> for i in `cat $infile`; do echo "$i"; done; exit
>
> and the stupid sucker is gagging on the "*" in the $infile - it has
> nothing to do with the conditionals whatsoever
>
> Evidently when it assigns the line "**** START OF ..." it actually tries
> to execute the first 4 files it finds in the directory - $#!%


* is the REGEXP symbol for 0 or more of something. Think you should find a
different symbol for that line or find a way to escape it, such as with ' '
around the string to get it treated as a literal rather than a shell evaluated
expression.

e.g.

$START = "*"
$DONE = $START

will tell bash that wherever you try to use $START will mean to use the REGEXP
char * and evaluate it and then assign that to $DONE, so $DONE won't be * but
whatever the shell interpreted it to be. Whereas $START = '*' won't evaluate
the * but assign it literally to $START.
---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss