Does filename expansion failing to match any file cause a script to exit with 1?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
From Bash Manual, for filename expansion:
If the
nullglob
option is set, and no matches are found, the word is removed.
My following script will return exit status 1.
Can filename expansion failing to match any jpg file in my current directory cause my script to exit with 1?
How can I rule out other possibility for exit status 1?
Thanks.
shopt -s nullglob
for i in *.png,jpg;
do
filename=$i##*/
basename=$filename%.*
[ ! -e $basename.pdf ] && convert "$i" $basename.pdf ;
done
bash
add a comment |Â
up vote
0
down vote
favorite
From Bash Manual, for filename expansion:
If the
nullglob
option is set, and no matches are found, the word is removed.
My following script will return exit status 1.
Can filename expansion failing to match any jpg file in my current directory cause my script to exit with 1?
How can I rule out other possibility for exit status 1?
Thanks.
shopt -s nullglob
for i in *.png,jpg;
do
filename=$i##*/
basename=$filename%.*
[ ! -e $basename.pdf ] && convert "$i" $basename.pdf ;
done
bash
Run the script withbash -x
to see where it exits exactly, and why.
â Stephen Kitt
Sep 26 '17 at 11:30
Does not exit with status 1 here, when running in a directory with no files matching the pattern.
â Kusalananda
Sep 26 '17 at 11:34
@Kusalananda thanks. withoutshopt -s nullglob
, will no matching cause your script exit with 1?
â Tim
Sep 26 '17 at 11:35
@Tim Yes, since the commands in the loop fail.
â Kusalananda
Sep 26 '17 at 11:36
@Stephen: Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post.
â Tim
Sep 26 '17 at 11:39
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
From Bash Manual, for filename expansion:
If the
nullglob
option is set, and no matches are found, the word is removed.
My following script will return exit status 1.
Can filename expansion failing to match any jpg file in my current directory cause my script to exit with 1?
How can I rule out other possibility for exit status 1?
Thanks.
shopt -s nullglob
for i in *.png,jpg;
do
filename=$i##*/
basename=$filename%.*
[ ! -e $basename.pdf ] && convert "$i" $basename.pdf ;
done
bash
From Bash Manual, for filename expansion:
If the
nullglob
option is set, and no matches are found, the word is removed.
My following script will return exit status 1.
Can filename expansion failing to match any jpg file in my current directory cause my script to exit with 1?
How can I rule out other possibility for exit status 1?
Thanks.
shopt -s nullglob
for i in *.png,jpg;
do
filename=$i##*/
basename=$filename%.*
[ ! -e $basename.pdf ] && convert "$i" $basename.pdf ;
done
bash
bash
edited Sep 26 '17 at 11:38
asked Sep 26 '17 at 11:29
Tim
23k66225408
23k66225408
Run the script withbash -x
to see where it exits exactly, and why.
â Stephen Kitt
Sep 26 '17 at 11:30
Does not exit with status 1 here, when running in a directory with no files matching the pattern.
â Kusalananda
Sep 26 '17 at 11:34
@Kusalananda thanks. withoutshopt -s nullglob
, will no matching cause your script exit with 1?
â Tim
Sep 26 '17 at 11:35
@Tim Yes, since the commands in the loop fail.
â Kusalananda
Sep 26 '17 at 11:36
@Stephen: Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post.
â Tim
Sep 26 '17 at 11:39
add a comment |Â
Run the script withbash -x
to see where it exits exactly, and why.
â Stephen Kitt
Sep 26 '17 at 11:30
Does not exit with status 1 here, when running in a directory with no files matching the pattern.
â Kusalananda
Sep 26 '17 at 11:34
@Kusalananda thanks. withoutshopt -s nullglob
, will no matching cause your script exit with 1?
â Tim
Sep 26 '17 at 11:35
@Tim Yes, since the commands in the loop fail.
â Kusalananda
Sep 26 '17 at 11:36
@Stephen: Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post.
â Tim
Sep 26 '17 at 11:39
Run the script with
bash -x
to see where it exits exactly, and why.â Stephen Kitt
Sep 26 '17 at 11:30
Run the script with
bash -x
to see where it exits exactly, and why.â Stephen Kitt
Sep 26 '17 at 11:30
Does not exit with status 1 here, when running in a directory with no files matching the pattern.
â Kusalananda
Sep 26 '17 at 11:34
Does not exit with status 1 here, when running in a directory with no files matching the pattern.
â Kusalananda
Sep 26 '17 at 11:34
@Kusalananda thanks. without
shopt -s nullglob
, will no matching cause your script exit with 1?â Tim
Sep 26 '17 at 11:35
@Kusalananda thanks. without
shopt -s nullglob
, will no matching cause your script exit with 1?â Tim
Sep 26 '17 at 11:35
@Tim Yes, since the commands in the loop fail.
â Kusalananda
Sep 26 '17 at 11:36
@Tim Yes, since the commands in the loop fail.
â Kusalananda
Sep 26 '17 at 11:36
@Stephen: Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post.
â Tim
Sep 26 '17 at 11:39
@Stephen: Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post.
â Tim
Sep 26 '17 at 11:39
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
No, setting the nullglob
shell option and failing to expand a glob pattern will not cause the script to exit with a non-zero exit status (and matching filenames with glob patterns in general does not change the $?
shell variable).
Not setting nullglob
will make convert
fail (unless there are files with the literal names *.jpg
and *.png
in the current directory), and it will exit with an exit status of 1.
Since this is the last executed command in the script, the script will exit with this exit status.
After update to script in question:
The script now exits with a non-zero exit status if a PDF file exists for the last image file processed, due to the [ ! -e ... ]
test (this is the last command executed in the script in that case).
If this is unwanted, use
[ ! -e "$basename.pdf" ] && convert "$i" "$basename.pdf" || true
(note also the added quoting)
Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post. Can that be the reason for script exist status 1? How can I suppress that cause of exit status 1?
â Tim
Sep 26 '17 at 11:39
@Tim See update.
â Kusalananda
Sep 26 '17 at 11:53
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
No, setting the nullglob
shell option and failing to expand a glob pattern will not cause the script to exit with a non-zero exit status (and matching filenames with glob patterns in general does not change the $?
shell variable).
Not setting nullglob
will make convert
fail (unless there are files with the literal names *.jpg
and *.png
in the current directory), and it will exit with an exit status of 1.
Since this is the last executed command in the script, the script will exit with this exit status.
After update to script in question:
The script now exits with a non-zero exit status if a PDF file exists for the last image file processed, due to the [ ! -e ... ]
test (this is the last command executed in the script in that case).
If this is unwanted, use
[ ! -e "$basename.pdf" ] && convert "$i" "$basename.pdf" || true
(note also the added quoting)
Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post. Can that be the reason for script exist status 1? How can I suppress that cause of exit status 1?
â Tim
Sep 26 '17 at 11:39
@Tim See update.
â Kusalananda
Sep 26 '17 at 11:53
add a comment |Â
up vote
1
down vote
accepted
No, setting the nullglob
shell option and failing to expand a glob pattern will not cause the script to exit with a non-zero exit status (and matching filenames with glob patterns in general does not change the $?
shell variable).
Not setting nullglob
will make convert
fail (unless there are files with the literal names *.jpg
and *.png
in the current directory), and it will exit with an exit status of 1.
Since this is the last executed command in the script, the script will exit with this exit status.
After update to script in question:
The script now exits with a non-zero exit status if a PDF file exists for the last image file processed, due to the [ ! -e ... ]
test (this is the last command executed in the script in that case).
If this is unwanted, use
[ ! -e "$basename.pdf" ] && convert "$i" "$basename.pdf" || true
(note also the added quoting)
Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post. Can that be the reason for script exist status 1? How can I suppress that cause of exit status 1?
â Tim
Sep 26 '17 at 11:39
@Tim See update.
â Kusalananda
Sep 26 '17 at 11:53
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
No, setting the nullglob
shell option and failing to expand a glob pattern will not cause the script to exit with a non-zero exit status (and matching filenames with glob patterns in general does not change the $?
shell variable).
Not setting nullglob
will make convert
fail (unless there are files with the literal names *.jpg
and *.png
in the current directory), and it will exit with an exit status of 1.
Since this is the last executed command in the script, the script will exit with this exit status.
After update to script in question:
The script now exits with a non-zero exit status if a PDF file exists for the last image file processed, due to the [ ! -e ... ]
test (this is the last command executed in the script in that case).
If this is unwanted, use
[ ! -e "$basename.pdf" ] && convert "$i" "$basename.pdf" || true
(note also the added quoting)
No, setting the nullglob
shell option and failing to expand a glob pattern will not cause the script to exit with a non-zero exit status (and matching filenames with glob patterns in general does not change the $?
shell variable).
Not setting nullglob
will make convert
fail (unless there are files with the literal names *.jpg
and *.png
in the current directory), and it will exit with an exit status of 1.
Since this is the last executed command in the script, the script will exit with this exit status.
After update to script in question:
The script now exits with a non-zero exit status if a PDF file exists for the last image file processed, due to the [ ! -e ... ]
test (this is the last command executed in the script in that case).
If this is unwanted, use
[ ! -e "$basename.pdf" ] && convert "$i" "$basename.pdf" || true
(note also the added quoting)
edited Sep 26 '17 at 12:25
answered Sep 26 '17 at 11:38
Kusalananda
106k14209327
106k14209327
Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post. Can that be the reason for script exist status 1? How can I suppress that cause of exit status 1?
â Tim
Sep 26 '17 at 11:39
@Tim See update.
â Kusalananda
Sep 26 '17 at 11:53
add a comment |Â
Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post. Can that be the reason for script exist status 1? How can I suppress that cause of exit status 1?
â Tim
Sep 26 '17 at 11:39
@Tim See update.
â Kusalananda
Sep 26 '17 at 11:53
Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post. Can that be the reason for script exist status 1? How can I suppress that cause of exit status 1?
â Tim
Sep 26 '17 at 11:39
Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post. Can that be the reason for script exist status 1? How can I suppress that cause of exit status 1?
â Tim
Sep 26 '17 at 11:39
@Tim See update.
â Kusalananda
Sep 26 '17 at 11:53
@Tim See update.
â Kusalananda
Sep 26 '17 at 11:53
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f394514%2fdoes-filename-expansion-failing-to-match-any-file-cause-a-script-to-exit-with-1%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Run the script with
bash -x
to see where it exits exactly, and why.â Stephen Kitt
Sep 26 '17 at 11:30
Does not exit with status 1 here, when running in a directory with no files matching the pattern.
â Kusalananda
Sep 26 '17 at 11:34
@Kusalananda thanks. without
shopt -s nullglob
, will no matching cause your script exit with 1?â Tim
Sep 26 '17 at 11:35
@Tim Yes, since the commands in the loop fail.
â Kusalananda
Sep 26 '17 at 11:36
@Stephen: Thanks. I updated my script, because I missed the checking the pdf file existence in my oriignal post.
â Tim
Sep 26 '17 at 11:39