Bash difference or preferred negation statementbash if statement behaviour questionPreferred way to install bash functions?Is there any major difference when comparing a variable as a string or as an intBash if statement [: missing `]' errorscript for automount, using if statement. cannot got the resultWhy is my elif being treated as an else statement in my bash script?Usage of -n and -z in test built in - Bashbash if statement different behaviourWTH - command not found - if statement - bash scriptDifference between piping and command expansion
Does the growth of home value benefit from compound interest?
How do I calculate APR from monthly instalments?
How is it possible that Gollum speaks Westron?
How to generate random points without duplication?
Through what methods and mechanisms can a multi-material FDM printer operate?
Secure offsite backup, even in the case of hacker root access
Fair use: Instructor sharing notes from textbooks
Reading two lines in piano
How to make a setting relevant?
Implement Homestuck's Catenative Doomsday Dice Cascader
Word for a small burst of laughter that can't be held back
Will TSA allow me to carry a Continuous Positive Airway Pressure (CPAP)/sleep apnea device?
Ancestor born in Bristol City workhouse?
Traffic law UK, pedestrians
What is the traditional way of earning a doctorate in Germany?
How were concentration and extermination camp guards recruited?
Is it a problem that pull requests are approved without any comments
What happens if you do emergency landing on a US base in middle of the ocean?
Can a 2nd-level sorcerer use sorcery points to create a 2nd-level spell slot?
How bad would a partial hash leak be, realistically?
C SIGINT signal in Linux
Importance sampling estimation of power function
Incremental Ranges!
My coworkers think I had a long honeymoon. Actually I was diagnosed with cancer. How do I talk about it?
Bash difference or preferred negation statement
bash if statement behaviour questionPreferred way to install bash functions?Is there any major difference when comparing a variable as a string or as an intBash if statement [: missing `]' errorscript for automount, using if statement. cannot got the resultWhy is my elif being treated as an else statement in my bash script?Usage of -n and -z in test built in - Bashbash if statement different behaviourWTH - command not found - if statement - bash scriptDifference between piping and command expansion
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Is there a difference in bash, or a preferred usage of negation of a statement?
if ! [[ -z "$var" ]]; then
do_something
fi
Versus
if [[ ! -z "$var" ]]; then
do_something
fi
bash shell-script test
add a comment |
Is there a difference in bash, or a preferred usage of negation of a statement?
if ! [[ -z "$var" ]]; then
do_something
fi
Versus
if [[ ! -z "$var" ]]; then
do_something
fi
bash shell-script test
add a comment |
Is there a difference in bash, or a preferred usage of negation of a statement?
if ! [[ -z "$var" ]]; then
do_something
fi
Versus
if [[ ! -z "$var" ]]; then
do_something
fi
bash shell-script test
Is there a difference in bash, or a preferred usage of negation of a statement?
if ! [[ -z "$var" ]]; then
do_something
fi
Versus
if [[ ! -z "$var" ]]; then
do_something
fi
bash shell-script test
bash shell-script test
edited 7 hours ago
Rui F Ribeiro
42.7k1688147
42.7k1688147
asked 8 hours ago
guillermo chamorroguillermo chamorro
1456
1456
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
! [[ expression ]]
This will be true if the entire test returns false
[[ ! expression ]]
This will be true if the individual expression returns false.
Since the test can be a compound expression this can be very different. For example:
$ [[ ! 0 -eq 1 || 1 -eq 1 ]] && echo yes || echo no
yes
$ ! [[ 0 -eq 1 || 1 -eq 1 ]] && echo yes || echo no
no
Personally I prefer to use the negation inside the test construct where applicable but it's perfectly fine outside depending on your intent.
add a comment |
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%2f522349%2fbash-difference-or-preferred-negation-statement%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
! [[ expression ]]
This will be true if the entire test returns false
[[ ! expression ]]
This will be true if the individual expression returns false.
Since the test can be a compound expression this can be very different. For example:
$ [[ ! 0 -eq 1 || 1 -eq 1 ]] && echo yes || echo no
yes
$ ! [[ 0 -eq 1 || 1 -eq 1 ]] && echo yes || echo no
no
Personally I prefer to use the negation inside the test construct where applicable but it's perfectly fine outside depending on your intent.
add a comment |
! [[ expression ]]
This will be true if the entire test returns false
[[ ! expression ]]
This will be true if the individual expression returns false.
Since the test can be a compound expression this can be very different. For example:
$ [[ ! 0 -eq 1 || 1 -eq 1 ]] && echo yes || echo no
yes
$ ! [[ 0 -eq 1 || 1 -eq 1 ]] && echo yes || echo no
no
Personally I prefer to use the negation inside the test construct where applicable but it's perfectly fine outside depending on your intent.
add a comment |
! [[ expression ]]
This will be true if the entire test returns false
[[ ! expression ]]
This will be true if the individual expression returns false.
Since the test can be a compound expression this can be very different. For example:
$ [[ ! 0 -eq 1 || 1 -eq 1 ]] && echo yes || echo no
yes
$ ! [[ 0 -eq 1 || 1 -eq 1 ]] && echo yes || echo no
no
Personally I prefer to use the negation inside the test construct where applicable but it's perfectly fine outside depending on your intent.
! [[ expression ]]
This will be true if the entire test returns false
[[ ! expression ]]
This will be true if the individual expression returns false.
Since the test can be a compound expression this can be very different. For example:
$ [[ ! 0 -eq 1 || 1 -eq 1 ]] && echo yes || echo no
yes
$ ! [[ 0 -eq 1 || 1 -eq 1 ]] && echo yes || echo no
no
Personally I prefer to use the negation inside the test construct where applicable but it's perfectly fine outside depending on your intent.
edited 8 hours ago
answered 8 hours ago
Jesse_bJesse_b
16k33978
16k33978
add a comment |
add a comment |
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%2f522349%2fbash-difference-or-preferred-negation-statement%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