bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash shows an error message about unpaired quotes, but they are pair


From: Greg Wooledge
Subject: Re: bash shows an error message about unpaired quotes, but they are paired
Date: Tue, 27 Mar 2018 08:46:13 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Mon, Mar 26, 2018 at 09:54:21PM +0200, f.de.kruijf@gmail.com wrote:
> #!/bin/bash
> 
> run () {
>    echo "Running: ${*}"
>    eval ${*}

If you're going to do it this way, that should be   eval "$*"  with the
quotes.

I strongly recommend NOT attempting this.  If anything, this way would
be slightly better:

run() {
    echo "Running $*"
    "$@"
    ...
}
run my command "with normally quoted" "${arguments[@]}"

That one allows arguments that have whitespace, but not redirections.
The "$*" variant allows redirections but not whitespace (without
additional quoting).

However, I consider both of them quite bad.  See
https://mywiki.wooledge.org/BashFaq/050

Especially 
https://mywiki.wooledge.org/BashFAQ/050#I_want_a_log_of_my_script.27s_actions

On Mon, Mar 26, 2018 at 04:05:02PM -0600, Eduardo Bustamante wrote:
> On Mon, Mar 26, 2018 at 1:54 PM,  <f.de.kruijf@gmail.com> wrote:
> > run 'sed -i "6a\find /srv/cowrie/log/ -mtime +7 -name \'cowrie.*\' -delete" 
> > cowrietest'
> 
> That's not how you escape single quotes within single quotes. Read:
> https://mywiki.wooledge.org/Quotes#Types_of_quoting
> 
> The proper way would be: run 'sed -i "6a\find /srv/cowrie/log/ -mtime
> +7 -name '\''cowrie.*'\''...

Or with $'...' quoting.  But still, I would scrap this altogether.
If I had to do it (forced at gunpoint or being paid to do it), then I
would use the "$@" variant which permits arbitrary arguments, because
I consider that far more important than being able to "submit and log"
redirections or pipelines.

P.S. what in the hell is that sed command even DOING?!  It looks like
you are writing a shell script that writes a shell command (wrapped in
extra quotes for submission to this rather hideous run function) which
invokes GNU sed to edit-in-place (BLLLLLAAARGGGH!) a file which may or
may not be a shell script already, and sed is attempting to add a shell
command to this file, and it's a nontrivial shell command with its
own layers of quoting.  Dear gods!  What an abomination.  You've got
like 4 different layers of commands wrapped inside each other.

Stop it!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]