Re: [Help-bash] A string handling question please.
From:
Greg Wooledge
Subject:
Re: [Help-bash] A string handling question please.
Date:
Wed, 25 Jul 2018 09:52:06 -0400
User-agent:
NeoMutt/20170113 (1.7.2)
On Tue, Jul 24, 2018 at 12:10:00AM +0000, George R Goffe wrote:
> I'm writing a function that will build a string based on the args passed to
> it and ultimately be executed as a bash command or commands linked via pipes.
"I'm trying to put a command in a variable, but the complex cases always fail!"
https://mywiki.wooledge.org/BashFAQ/050
> invoke doit() with args a b c d e: doit $a $b $c $d $ehttps://mywiki.wooledge.org/Quotes
> generate command" xx=$(history | $a | $b | $c -z | $d | $e) and then execute
> $xx.
What on earth is the actual goal you're trying to achieve here? Why
is there a hard-coded "-z" argument to the third command in the list?
At first glance I would have thought the goal was "take a list of simple
commands and run them all as a pipeline", but the hard-coded -z destroys
that notion. The hard-coded -z is just so incredibly WEIRD that the only
goal I can think of is "I know the third command in the list is going to
be sort and I know the sort command will need -z", but then if you know
this much a priori about the list, why not simply write the entire list
as a single function and then call it?
If the goal really is "take a list of commands and run them all as a
pipeline", then I suggest not doing it in bash. Bash is not well suited
for passing lists of lists around (each simple command being a list of
its own, because it has arguments, and then the outer list being the
list of all the simple commands). Other languages like Tcl are better
for that.