[NTLUG:Discuss] Help with script
Leroy Tennison
leroy_tennison at prodigy.net
Sat Mar 20 03:01:00 CDT 2010
George Lass wrote:
> When I tried to run what you wrote, it seems that the semicolon's were not being processed as one would have thought in your grep; if; then; fi sequence.
>
> You might try something like this:
>
>
> function pretty {
> echo "<tr><td> $1 </td></tr><tr><td>"
> shift
> echo $*
> echo "</td></tr>"
> }
>
>
> pretty 'grep 127 /etc/hosts' `grep 127 /etc/hosts ; if [[ $? = 1 ]] ; then echo
> IP Address 127 not found ; fi`
>
> pretty 'grep 9999 /etc/hosts' `grep 9999 /etc/hosts ; if [[ $? = 1 ]] ; then echo IP Address 9999 not found ; fi`
>
>
>
>
> # Note that the "grep; if; then; fi" sequence is enclosed in grave marks and not single quotes.
>
> George
>
> --- On Thu, 3/18/10, Leroy Tennison <leroy_tennison at prodigy.net> wrote:
>
>
>> From: Leroy Tennison <leroy_tennison at prodigy.net>
>> Subject: [NTLUG:Discuss] Help with script
>> To: "NTLUG Discussion List" <discuss at ntlug.org>
>> Date: Thursday, March 18, 2010, 1:08 AM
>> I'm attempting to "wrap" HTML around
>> a script's output in order to make
>> the output "pretty" but I also need to output the "real"
>> commands in the
>> script (but not the ones doing the "beautification").
>> My current
>> attempt looks like:
>>
>> function pretty {
>> echo "<tr><td>" $@
>> "</td></tr><tr><td>"
>> $@
>> echo "</td></tr>"
>> }
>>
>>
>> Using:
>>
>> pretty grep 127 /etc/hosts
>>
>>
>> works as expected.
>>
>> I've tried everything I can think of to get the following
>> to work but
>> without success:
>>
>> pretty grep 127 /etc/hosts; if [[ $? = 1 ]];
>> then echo "127 not
>> found"; fi
>>
>>
>> I've put single quotes around the entire command, I've put
>> double quotes
>> around it, I've tried setting each piece of the command
>> (the parts
>> between the semicolons) to a variable and using the
>> variables in the
>> function. Nothing works, what I get is:
>>
>> pretty[(a line number)]: if: not found [No such file or
>> directory]
>> pretty[(a line number)]: then: not found [No such file or
>> directory]
>> pretty[(a line number)]: fi: not found [No such file or
>> directory]
>>
>> It seems that $@ has to be an executable program, nothing
>> else works.
>> Executing the script with -v or -x doesn't add much except
>> parts of the
>> command are being quoted. Any one know how to solve
>> this problem? Much
>> thanks.
>>
>> _______________________________________________
>> http://www.ntlug.org/mailman/listinfo/discuss
>>
>>
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
>
Hmmm, put it in graves, I'll note that for future reference.
More information about the Discuss
mailing list