[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
failglob handling
From: |
Thomas Deutschmann |
Subject: |
failglob handling |
Date: |
Fri, 3 Aug 2018 15:29:33 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 Thunderbird/52.9.1 |
Hi,
please see the following script:
> #!/bin/bash
> shopt -s failglob
> if [[ $? -ne 0 ]]; then
> echo 'shopt failed'
> exit 1
> fi
>
> # Let's view current options just to be sure
> shopt -p
>
> # The following glob should fail because /foo/bar does not exist ...
> # Due to 'failglob' option, bash should stop here
> echo /foo/bar/*
>
> # This code should never run if previous glob failed
> echo Still alive
Is the assumption true that "Still alive" should *never* be printed
when "/foo/bar" does not exist?
With bash 4.4-5 (aka 4.4.12(1)) on Debian Stretch and 4.4.23(1) on Gentoo,
"Still alive" will be printed.
When you add "set -e" to the beginning, execution will stop immediately
after the failing glob, i.e. no "Still alive" will be printed.
However, see the following interesting difference between semicolons and
newlines:
> $ echo "shopt -s failglob; echo /foo/bar/*; echo alive; " | bash
> bash: line 1: no match: /foo/bar/*
> $ echo "shopt -s failglob; echo /foo/bar/*; echo alive; " | sed 's:; :\n:g' |
> bash
> bash: line 2: no match: /foo/bar/*
> alive
> $ echo "set -e; shopt -s failglob; echo /foo/bar/*; echo alive; " | sed 's:;
> :\n:g' | bash
> bash: line 3: no match: /foo/bar/*
> $
--
Regards,
Thomas Deutschmann / Gentoo Linux Developer
C4DD 695F A713 8F24 2AA1 5638 5849 7EE5 1D5D 74A5
signature.asc
Description: OpenPGP digital signature
- failglob handling,
Thomas Deutschmann <=