Does filename expansion failing to match any file cause a script to exit with 1?

The name of the pictureThe name of the pictureThe name of the pictureClash 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









share|improve this question























  • 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














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









share|improve this question























  • 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












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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 26 '17 at 11:38

























asked Sep 26 '17 at 11:29









Tim

23k66225408




23k66225408











  • 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
















  • 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















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










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)






share|improve this answer






















  • 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










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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)






share|improve this answer






















  • 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














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)






share|improve this answer






















  • 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












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)






share|improve this answer














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)







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay