Timeline for bash if not multiple conditions without subshell?
Current License: CC BY-SA 3.0
21 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 3, 2022 at 0:35 | answer | added | Mario Palumbo | timeline score: 2 | |
| Dec 7, 2015 at 9:38 | comment | added | terdon♦ | @alexgray there's no such thing as a cross-site duplicate. Duplicates only refer to this site. We don't want the same question posted by the same person on different sites of the SE network but similar questions by different people are fine. In any case, that is not a dupe. That one is just asking how to combine conditionals, here the question is about negating a bunch of already combined conditionals without spawning a subshell. | |
| Dec 7, 2015 at 6:48 | comment | added | Wildcard | Not a duplicate at all. The subject of this question isn't even touched upon over there. | |
| Dec 7, 2015 at 6:07 | comment | added | alex gray | Dupe! Cross-site dupe! Oh no! stackoverflow.com/questions/6916559/… | |
| Dec 4, 2015 at 1:48 | answer | added | woodengod | timeline score: 7 | |
| Dec 4, 2015 at 0:22 | answer | added | G-Man Says 'Reinstate Monica' | timeline score: 2 | |
| Dec 3, 2015 at 23:17 | history | tweeted | twitter.com/StackUnix/status/672555363858849792 | ||
| Dec 3, 2015 at 21:29 | comment | added | Wildcard | Related question (similar but not as much discussion and answers not so helpful): unix.stackexchange.com/q/156885/135943 | |
| Dec 3, 2015 at 21:06 | comment | added | mikeserv |
@Wildcard - [ ! -e file/. ] && [ -r file ] will drop directories. negate it as you like. of course, that's what -d does.
|
|
| Dec 3, 2015 at 21:02 | comment | added | Wildcard |
@mikeserv: Neither, the conditions are made up for the purpose of illustration and for simplicity. My actual use case is for readable files, more like if [ ! -d mydir ] || [ ! -r mydir/file1 ] || [ ! -r mydir/file2 ] ; then although now I look at it, (1) the -d check is unnecessary given the following two checks and (2) if file1 and/or file2 were readable dirs instead of readable files, my script would incorrectly validate them. That's a corner case though.
|
|
| Dec 3, 2015 at 20:50 | answer | added | mikeserv | timeline score: 5 | |
| Dec 3, 2015 at 19:27 | answer | added | zwol | timeline score: 10 | |
| Dec 3, 2015 at 18:53 | vote | accept | Wildcard | ||
| Dec 3, 2015 at 18:42 | comment | added | DopeGhoti |
Yes, I just tested if [ ! 1 -eq 2 ] && [ ! 2 -eq 3 ]; then echo yep; fi and it works. I just always write tests with double-braces as a matter of habit. Also, to ensure it's not bash, I further tested if /bin/test ! 1 -eq 2 && /bin/test ! 2 -eq 3 ; then echo yep; fi and it works that way also.
|
|
| Dec 3, 2015 at 18:41 | answer | added | DopeGhoti | timeline score: 1 | |
| Dec 3, 2015 at 18:41 | comment | added | Wildcard | @DopeGhoti, does that work with single brackets? i.e. is that a bashism only or a POSIX portable syntax? | |
| Dec 3, 2015 at 18:39 | comment | added | DopeGhoti |
You can also negate inside the braces, e. g. if [[ ! -f file1 ]] && [[ ! -f file2 ]]; then
|
|
| Dec 3, 2015 at 18:36 | answer | added | cuonglm | timeline score: 53 | |
| Dec 3, 2015 at 18:34 | answer | added | David King | timeline score: 0 | |
| Dec 3, 2015 at 18:31 | comment | added | Wildcard |
I suppose I could also use boolean logic to determine the equivalent expression: if ! [ -f file1 ] || ! [ -f file 2 ] || ! [ -f file3 ] ; then but I'd like a more general answer.
|
|
| Dec 3, 2015 at 18:30 | history | asked | Wildcard | CC BY-SA 3.0 |