[psas-software] Script help please

Jason Holt jason at lunkwill.org
Tue Nov 1 16:59:54 PST 2005


Wow, what a pain.  This works:

#!/bin/bash
# Eliminate sequences of '<space><tab>'
REGEXP='s/ \t//g'
echo "sed Regular Expression is: -->"$REGEXP"<--"
sed "$REGEXP"

Apparently variables get replaced before the shell splits up arguments.  That 
makes sense, I guess, since we want this to work:

FOO='ls -l'
$FOO

Rather than returning an error about not finding a command named "ls -l" (as 
opposed to a command named ls, then passing it -l as an argument).  So I tried 
this:

sed '$REGEXP'

But then, the ' keeps $REGEXP from getting expanded at all, so the command 
'sed $REGEXP' is what runs (with the $ and everything).  Using sed "$REGEXP", 
the " lets the variable be expanded, but still keeps it together as a single 
argument.

 						-J


On Tue, 1 Nov 2005, jay1 wrote:

> When I make the suggested change to the script I get:
>
> jay at rocket:~/bin$ cat smData2 | ./exp2
> sed Regular Expression is: -->s/ \t//g<--
> sed² -e expression #1, char 2: unterminated `s¹ command
> jay at rocket:~/bin$
>
>
>>>>  Jason Holt  < jason at lunkwill.org >  on 11/1/05 4:16 PM wrote <<<
>
>>
>> On Tue, 1 Nov 2005, Jay Beck wrote:
>>
>>>> REGEXP="'s/ \t//g'"
>>>>
>>>> echo "sed Regular Expression is: -->"$REGEXP"<--"
>>>>
>>>> sed $REGEXP
>>>>
>>>> jay at rocket:~/bin$ cat smData2 | ./exp2
>>>> sed Regular Expression is: -->'s/ \t//g'<--
>>>> sed: -e expression #1, char 1: unknown command: `''
>>>> jay at rocket:~/bin$
>>>> can anyone explain why the script acts different and correct it?
>>
>> You're doubly quoting the string, so the ' stays in.  Try:
>>
>> REGEXP='s/ \t//g'
>>
>>       -J
>>
>
>
>


More information about the psas-avionics mailing list