[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Set verbose Flag Inside if-block
From: |
Sysadmin Lists |
Subject: |
Re: Set verbose Flag Inside if-block |
Date: |
Mon, 17 Apr 2023 22:23:46 +0200 (CEST) |
> Well, until someone can convince Chet to re-write Bash to make this flag
> useful, I've come up with a ridiculous workaround:
>
> $ cat tmpfile.sh
> if true
> then
> printf "echo foo bar baz\n" | sh -v
> fi
>
> $ ./tmpfile.sh
> echo foo bar baz
> foo bar baz
>
> Being able to selectively echo commands inside if-blocks makes sense. The -v
> flag is a bit of a fraud the way it's currently implemented.
>
> PS. I don't know why this doesn't work:
> (set -ve; echo $-; echo foo bar baz; set +ve)
>
> That should create a sub-shell with the v flag set on the entire command line.
It's not great, but it's not vomit-inducing either:
$ cat tmpfile.sh
o=printf\ '%s\n'
if true
then
var="* foo"
$o "echo ${var/\*}" | sh -v
$o "ls -d /tmp/" | sh -v
$o "date" | sh -v
fi
$ ./tmpfile.sh
echo foo
foo
ls -d /tmp/
/tmp/
date
Mon Apr 17 13:23:42 PDT 2023
--
Sent with https://mailfence.com
Secure and private email
Re: Set verbose Flag Inside if-block,
Sysadmin Lists <=