Re: Rewriting a shell script

From: Colin Booth <cathexis_at_gmail.com>
Date: Sun, 29 Nov 2015 21:57:45 -0800

On Sun, Nov 29, 2015 at 5:04 PM, Scott Mebberson
<scott_at_scottmebberson.com> wrote:
>
> Sorry for the noob question. But how can I pass the value to awk without it
> complaining?
>
Hi Scott,

I'm pretty sure that your single quotes are confusing the execline
parser. Since awk accepts either single or double quotes as
delimiters, switching to double quotes should fix it. Your script also
has a few issues that you'd have come across once fixing the awk
issue. Try the following out instead:

#!/command/execlineb -P
s6-envdir -fn env
importas -un HOSTNAME HOSTNAME
backtick -in A {
pipeline { getent hosts ${HOSTNAME} }
awk "{print $1}"
}
import -u A
...

Specifically, you need the -n option for importas, otherwise you'll
end up sending a newline to awk and getting back a blank line. You can
also swap out importas HOSTNAME HOSTNAME for import HOSTNAME but
that's stylistic.

All that said, you don't need to call awk in a pipeline to get your ip
out of your environment. The following will do the same:
#!/command/execlineb -P
s6-envdir -fn env
importas -un HOSTNAME HOSTNAME
backtick -in A { /usr/bin/getent hosts ${HOSTNAME} }
import -u A
define -sn B ${A}
...

define -sn B ${A} does essentially the same thing as awk '{print $1}'.
You just need to bounce the value in and out of the environment a few
times.

Cheers!

-- 
"If the doors of perception were cleansed every thing would appear to
man as it is, infinite. For man has closed himself up, till he sees
all things thru' narrow chinks of his cavern."
  --  William Blake
Received on Mon Nov 30 2015 - 05:57:45 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC