Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14438 > unrolled thread

failglob handling

Started byThomas Deutschmann <whissi@gentoo.org>
First post2018-08-03 15:29 +0200
Last post2018-08-03 15:29 +0200
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug


Contents

  failglob handling Thomas Deutschmann <whissi@gentoo.org> - 2018-08-03 15:29 +0200

#14438 — failglob handling

FromThomas Deutschmann <whissi@gentoo.org>
Date2018-08-03 15:29 +0200
Subjectfailglob handling
Message-ID<mailman.4651.1533307346.1292.bug-bash@gnu.org>

[Multipart message — attachments visible in raw view] — view raw

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

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web