make bash exit if declare statement failsBash: handling “[[ statement ]] || echo problem found ; exit 1”...
Where have Brexit voters gone?
Why aren't space telescopes put in GEO?
Find the three digit Prime number P from the given unusual relationships
How to respond to upset student?
What does ${!#} mean in Shell scripting?
Is it rude to call a professor by their last name with no prefix in a non-academic setting?
Using credit/debit card details vs swiping a card in a payment (credit card) terminal
Does this strict reading of the rules allow both Extra Attack and the Thirsting Blade warlock invocation to be used together?
Website returning plaintext password
Did 20% of US soldiers in Vietnam use heroin, 95% of whom quit afterwards?
What was the idiom for something that we take without a doubt?
What is the difference between singing and speaking?
Why most published works in medical imaging try reducing false positives?
Count Even Digits In Number
Remove CiviCRM and Drupal links / banner on profile form
Why did Jon Snow do this immoral act if he is so honorable?
Is the Indo-European language family made up?
Is it legal to have an abortion in another state or abroad?
Where's this lookout in Nova Scotia?
Can a British citizen living in France vote in both France and Britain in the European Elections?
Apt - strange requests to d16r8ew072anqo.cloudfront.net:80
Why were helmets and other body armour not commonplace in the 1800s?
What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?
Ethical issue - how can I better document what is happening?
make bash exit if declare statement fails
Bash: handling “[[ statement ]] || echo problem found ; exit 1” logicHow to set pipe of process after process substitution in bash so that process continues after script ends?What Bash Statement doesHow to automatically insert a string after the promptHow to make a special expandable phrase in bash?Exit the script if any statement failsBASH script: declare a variable inside CASE statement to use globallyWhy bash “read -t 0” does not see input?Bash script fails where command line worksWhat is “declare” in Bash?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
tl;dr I want bash to automatically exit after declare var=$(false)
.
My bash scripts use set -e
. However, when using declare
variable declaration idiom, the declare
appears to "block" returning the return code from a shell substitution.
$ var=$(false)
$ echo $?
1
$ declare var=$(false)
$ echo $?
0
Therefore, bash will not exit on error (given set -e
or set errexit
). I know I could test var
but that is too cumbersome after every declare
statement.
How to automatically exit bash after a failure during declare
?
bash bash-expansion
add a comment |
tl;dr I want bash to automatically exit after declare var=$(false)
.
My bash scripts use set -e
. However, when using declare
variable declaration idiom, the declare
appears to "block" returning the return code from a shell substitution.
$ var=$(false)
$ echo $?
1
$ declare var=$(false)
$ echo $?
0
Therefore, bash will not exit on error (given set -e
or set errexit
). I know I could test var
but that is too cumbersome after every declare
statement.
How to automatically exit bash after a failure during declare
?
bash bash-expansion
add a comment |
tl;dr I want bash to automatically exit after declare var=$(false)
.
My bash scripts use set -e
. However, when using declare
variable declaration idiom, the declare
appears to "block" returning the return code from a shell substitution.
$ var=$(false)
$ echo $?
1
$ declare var=$(false)
$ echo $?
0
Therefore, bash will not exit on error (given set -e
or set errexit
). I know I could test var
but that is too cumbersome after every declare
statement.
How to automatically exit bash after a failure during declare
?
bash bash-expansion
tl;dr I want bash to automatically exit after declare var=$(false)
.
My bash scripts use set -e
. However, when using declare
variable declaration idiom, the declare
appears to "block" returning the return code from a shell substitution.
$ var=$(false)
$ echo $?
1
$ declare var=$(false)
$ echo $?
0
Therefore, bash will not exit on error (given set -e
or set errexit
). I know I could test var
but that is too cumbersome after every declare
statement.
How to automatically exit bash after a failure during declare
?
bash bash-expansion
bash bash-expansion
edited 28 mins ago
JamesThomasMoon1979
asked 34 mins ago
JamesThomasMoon1979JamesThomasMoon1979
276211
276211
add a comment |
add a comment |
0
active
oldest
votes
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f520771%2fmake-bash-exit-if-declare-statement-fails%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f520771%2fmake-bash-exit-if-declare-statement-fails%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown