[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Set verbose Flag Inside if-block
From: |
Andreas Kusalananda Kähäri |
Subject: |
Re: Set verbose Flag Inside if-block |
Date: |
Sun, 16 Apr 2023 10:42:29 +0200 |
On Sun, Apr 16, 2023 at 04:54:41AM +0200, Sysadmin Lists wrote:
> What explains the difference here? Why does setting verbose inside the
> if-statement not echo the command, but setting x does, and setting verbose
> before the if-statement does, too?
>
> $ if true; then set -ve; echo $-; echo foo bar baz; set -ve; fi
> ehimvBHs
> foo bar baz
Using set -v causes the shell to print the input lines *as they are
read*. The line that contains the "set -v" command has already been
read, so it won't be outputted.
>
> $ set -ve; if true; then echo $-; echo foo bar baz; set -ve; fi
> set -ve; if true; then echo $-; echo foo bar baz; set -ve; fi
> ehimvBHs
> foo bar baz
No diference here, the line has already been read.
>
> $ if true; then set -xe; echo $-; echo foo bar baz; set -xe; fi
> + echo ehimvxBHs
> ehimvxBHs
> + echo foo bar baz
> foo bar baz
> + set -xe
Using set -x causes the shell to print commands *as they are executed*.
>
> $ set -xe; if true; then echo $-; echo foo bar baz; set -xe; fi
> set -xe; if true; then echo $-; echo foo bar baz; set -xe; fi
> + set -xe
> + true
> + echo ehimvxBHs
> ehimvxBHs
> + echo foo bar baz
> foo bar baz
> + set -xe
>
>
>
> --
> Sent with https://mailfence.com
> Secure and private email
--
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden
.