Re: Rewriting a shell script

From: Laurent Bercot <ska-skaware_at_skarnet.org>
Date: Mon, 30 Nov 2015 09:14:52 +0100

On 30/11/2015 06:57, Colin Booth wrote:
> I'm pretty sure that your single quotes are confusing the execline
> parser.

  That's the answer. execline only uses double quotes, it does not
understand single quotes.


> Since awk accepts either single or double quotes as
> delimiters

  Hm ? I don't think awk understand delimiters at all. It only
takes a single argument (in this case). The quotes are a shell
thing.


> define -sn B ${A} does essentially the same thing as awk '{print $1}'.

  Not at all, if ${A} contains whitespace! ${B} will then expand to
several words, but you only want the first one.
  I'd just do away with awk entirely and use cut instead:

-----
#!/usr/bin/execlineb -P

with-contenv
backtick -n BIND
{
   pipeline { import -u HOSTNAME getent hosts ${HOSTNAME} }
   cut -f1 -d" "
}
s6-setuidgid consul
consul agent
    -config-dir /etc/consul.d/bootstrap
    -bind ${BIND}
-----

  which is pretty much the exact translation of the shell
script, but using cut instead of awk.

-- 
  Laurent
Received on Mon Nov 30 2015 - 08:14:52 UTC

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