[NTLUG:Discuss] Help with script

Leroy Tennison leroy_tennison at prodigy.net
Thu Mar 18 01:08:25 CDT 2010


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.



More information about the Discuss mailing list