Shortening a long if/test string comparison
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am comparing multiple strings in bash. Currently I have a script that looks like this:
if [ "$f" != "A-C" ] && [ "$f" != "D-F" ] && [ "$f" != "G-I" ] && [ "$f" != "J-L" ] && [ "$f" != "M-O" ] && [ "$f" != "P-R" ] && [ "$f" != "S-U" ] && [ "$f" != "V-X" ] && [ "$f" != "Y&Z" ] && [ "$f" != "#" ]; then #if f is a directory
How can I shorten this?
scripting test
add a comment |Â
up vote
0
down vote
favorite
I am comparing multiple strings in bash. Currently I have a script that looks like this:
if [ "$f" != "A-C" ] && [ "$f" != "D-F" ] && [ "$f" != "G-I" ] && [ "$f" != "J-L" ] && [ "$f" != "M-O" ] && [ "$f" != "P-R" ] && [ "$f" != "S-U" ] && [ "$f" != "V-X" ] && [ "$f" != "Y&Z" ] && [ "$f" != "#" ]; then #if f is a directory
How can I shorten this?
scripting test
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am comparing multiple strings in bash. Currently I have a script that looks like this:
if [ "$f" != "A-C" ] && [ "$f" != "D-F" ] && [ "$f" != "G-I" ] && [ "$f" != "J-L" ] && [ "$f" != "M-O" ] && [ "$f" != "P-R" ] && [ "$f" != "S-U" ] && [ "$f" != "V-X" ] && [ "$f" != "Y&Z" ] && [ "$f" != "#" ]; then #if f is a directory
How can I shorten this?
scripting test
I am comparing multiple strings in bash. Currently I have a script that looks like this:
if [ "$f" != "A-C" ] && [ "$f" != "D-F" ] && [ "$f" != "G-I" ] && [ "$f" != "J-L" ] && [ "$f" != "M-O" ] && [ "$f" != "P-R" ] && [ "$f" != "S-U" ] && [ "$f" != "V-X" ] && [ "$f" != "Y&Z" ] && [ "$f" != "#" ]; then #if f is a directory
How can I shorten this?
scripting test
edited Dec 10 '17 at 15:39
Jeff Schaller
32k848109
32k848109
asked Dec 6 '17 at 7:36
scroobius
33
33
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Ended up with something like this:
[[ "$f" != +(A-C|D-F|G-I|J-L|M-O|P-R|S-U|V-X|Y&Z|#) ]]
1
I don't think you need the quotes on the right hand side (there's nothing special inA-C
to quote, it's not a character class without the brackets).@(foo|bar)
to match exactly once, with+
it'll match e.g.A-CJ-L
â ilkkachu
Dec 6 '17 at 8:09
@ilkkachu okay thanks edited the answer
â scroobius
Dec 7 '17 at 4:07
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Ended up with something like this:
[[ "$f" != +(A-C|D-F|G-I|J-L|M-O|P-R|S-U|V-X|Y&Z|#) ]]
1
I don't think you need the quotes on the right hand side (there's nothing special inA-C
to quote, it's not a character class without the brackets).@(foo|bar)
to match exactly once, with+
it'll match e.g.A-CJ-L
â ilkkachu
Dec 6 '17 at 8:09
@ilkkachu okay thanks edited the answer
â scroobius
Dec 7 '17 at 4:07
add a comment |Â
up vote
0
down vote
accepted
Ended up with something like this:
[[ "$f" != +(A-C|D-F|G-I|J-L|M-O|P-R|S-U|V-X|Y&Z|#) ]]
1
I don't think you need the quotes on the right hand side (there's nothing special inA-C
to quote, it's not a character class without the brackets).@(foo|bar)
to match exactly once, with+
it'll match e.g.A-CJ-L
â ilkkachu
Dec 6 '17 at 8:09
@ilkkachu okay thanks edited the answer
â scroobius
Dec 7 '17 at 4:07
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Ended up with something like this:
[[ "$f" != +(A-C|D-F|G-I|J-L|M-O|P-R|S-U|V-X|Y&Z|#) ]]
Ended up with something like this:
[[ "$f" != +(A-C|D-F|G-I|J-L|M-O|P-R|S-U|V-X|Y&Z|#) ]]
edited Dec 7 '17 at 4:08
answered Dec 6 '17 at 7:59
scroobius
33
33
1
I don't think you need the quotes on the right hand side (there's nothing special inA-C
to quote, it's not a character class without the brackets).@(foo|bar)
to match exactly once, with+
it'll match e.g.A-CJ-L
â ilkkachu
Dec 6 '17 at 8:09
@ilkkachu okay thanks edited the answer
â scroobius
Dec 7 '17 at 4:07
add a comment |Â
1
I don't think you need the quotes on the right hand side (there's nothing special inA-C
to quote, it's not a character class without the brackets).@(foo|bar)
to match exactly once, with+
it'll match e.g.A-CJ-L
â ilkkachu
Dec 6 '17 at 8:09
@ilkkachu okay thanks edited the answer
â scroobius
Dec 7 '17 at 4:07
1
1
I don't think you need the quotes on the right hand side (there's nothing special in
A-C
to quote, it's not a character class without the brackets). @(foo|bar)
to match exactly once, with +
it'll match e.g. A-CJ-L
â ilkkachu
Dec 6 '17 at 8:09
I don't think you need the quotes on the right hand side (there's nothing special in
A-C
to quote, it's not a character class without the brackets). @(foo|bar)
to match exactly once, with +
it'll match e.g. A-CJ-L
â ilkkachu
Dec 6 '17 at 8:09
@ilkkachu okay thanks edited the answer
â scroobius
Dec 7 '17 at 4:07
@ilkkachu okay thanks edited the answer
â scroobius
Dec 7 '17 at 4:07
add a comment |Â
Â
draft saved
draft discarded
Â
draft saved
draft discarded
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%2f409119%2fshortening-a-long-if-test-string-comparison%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