Pattern match does not work in bash scriptHow can I use inverse or negative wildcards when pattern matching...
How does strength of boric acid solution increase in presence of salicylic acid?
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?
Finding angle with pure Geometry.
Arthur Somervell: 1000 Exercises - Meaning of this notation
Why not use SQL instead of GraphQL?
Prove that NP is closed under karp reduction?
What typically incentivizes a professor to change jobs to a lower ranking university?
Collect Fourier series terms
Email Account under attack (really) - anything I can do?
Languages that we cannot (dis)prove to be Context-Free
Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)
What's the output of a record cartridge playing an out-of-speed record
How much RAM could one put in a typical 80386 setup?
Is it unprofessional to ask if a job posting on GlassDoor is real?
How old can references or sources in a thesis be?
Font hinting is lost in Chrome-like browsers (for some languages )
How to format long polynomial?
How to find program name(s) of an installed package?
In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?
Adding span tags within wp_list_pages list items
Can divisibility rules for digits be generalized to sum of digits
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
Why don't electron-positron collisions release infinite energy?
Pattern match does not work in bash script
How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?List all files that do not match pattern using lsWhy would I not leave extglob enabled in bash?Get the source directory of a Bash script from within the script itselfHow to check if a string contains a substring in BashHow to check if a program exists from a Bash script?How do I tell if a regular file does not exist in Bash?How do I split a string on a delimiter in Bash?Extract filename and extension in BashHow to concatenate string variables in BashReliable way for a Bash script to get the full path to itselfPassing parameters to a Bash functionEcho newline in Bash prints literal n
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Using the pattern match !("file1") does not work within a bash script but will work on the command line.
For example:
ls !("file1"|"file2")
This will list all files in directory except file1 and file2.
When that line is executed in a script this error is displayed:
./script.sh: line 1: syntax error near unexpected token `('
./script.sh: line 1: ` ls !("file1"|"file2") '
Regardless what is used rm -v !("file1"). The same error takes place. What is going on here why does this not work in a script?
linux bash glob extglob
New contributor
Ogden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Using the pattern match !("file1") does not work within a bash script but will work on the command line.
For example:
ls !("file1"|"file2")
This will list all files in directory except file1 and file2.
When that line is executed in a script this error is displayed:
./script.sh: line 1: syntax error near unexpected token `('
./script.sh: line 1: ` ls !("file1"|"file2") '
Regardless what is used rm -v !("file1"). The same error takes place. What is going on here why does this not work in a script?
linux bash glob extglob
New contributor
Ogden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Possible duplicate of How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?, List all files that do not match pattern using ls, etc. And related is Why would I not leave extglob enabled in bash?
– jww
10 hours ago
add a comment |
Using the pattern match !("file1") does not work within a bash script but will work on the command line.
For example:
ls !("file1"|"file2")
This will list all files in directory except file1 and file2.
When that line is executed in a script this error is displayed:
./script.sh: line 1: syntax error near unexpected token `('
./script.sh: line 1: ` ls !("file1"|"file2") '
Regardless what is used rm -v !("file1"). The same error takes place. What is going on here why does this not work in a script?
linux bash glob extglob
New contributor
Ogden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Using the pattern match !("file1") does not work within a bash script but will work on the command line.
For example:
ls !("file1"|"file2")
This will list all files in directory except file1 and file2.
When that line is executed in a script this error is displayed:
./script.sh: line 1: syntax error near unexpected token `('
./script.sh: line 1: ` ls !("file1"|"file2") '
Regardless what is used rm -v !("file1"). The same error takes place. What is going on here why does this not work in a script?
linux bash glob extglob
linux bash glob extglob
New contributor
Ogden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ogden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 16 hours ago
James Brown
20.5k42037
20.5k42037
New contributor
Ogden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 17 hours ago
OgdenOgden
634
634
New contributor
Ogden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Ogden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Ogden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Possible duplicate of How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?, List all files that do not match pattern using ls, etc. And related is Why would I not leave extglob enabled in bash?
– jww
10 hours ago
add a comment |
Possible duplicate of How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?, List all files that do not match pattern using ls, etc. And related is Why would I not leave extglob enabled in bash?
– jww
10 hours ago
Possible duplicate of How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?, List all files that do not match pattern using ls, etc. And related is Why would I not leave extglob enabled in bash?
– jww
10 hours ago
Possible duplicate of How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?, List all files that do not match pattern using ls, etc. And related is Why would I not leave extglob enabled in bash?
– jww
10 hours ago
add a comment |
3 Answers
3
active
oldest
votes
The extended glob syntax you are trying to use is turned off by default; you have to enable it separately in each script where you want to use it.
shopt -s extglob
Scripts should not use ls though I imagine you were using it merely as a placeholder here.
add a comment |
Globbing doesn't work that way unless you enable extglob shell opt. Instead, I recommend using find:
find . -maxdepth 1 -not -name '<NAME>' -or -name '<NAME>' -delete
before running this command with -delete ensure the output is correct
add a comment |
Method with default settings and no external procs:
for f in *; do [[ $f =~ ^file[12]$ ]] || echo "$f"; done
New contributor
vintnes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
Ogden is a new contributor. Be nice, and check out our Code of Conduct.
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%2fstackoverflow.com%2fquestions%2f55546727%2fpattern-match-does-not-work-in-bash-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The extended glob syntax you are trying to use is turned off by default; you have to enable it separately in each script where you want to use it.
shopt -s extglob
Scripts should not use ls though I imagine you were using it merely as a placeholder here.
add a comment |
The extended glob syntax you are trying to use is turned off by default; you have to enable it separately in each script where you want to use it.
shopt -s extglob
Scripts should not use ls though I imagine you were using it merely as a placeholder here.
add a comment |
The extended glob syntax you are trying to use is turned off by default; you have to enable it separately in each script where you want to use it.
shopt -s extglob
Scripts should not use ls though I imagine you were using it merely as a placeholder here.
The extended glob syntax you are trying to use is turned off by default; you have to enable it separately in each script where you want to use it.
shopt -s extglob
Scripts should not use ls though I imagine you were using it merely as a placeholder here.
edited 16 hours ago
answered 16 hours ago
tripleeetripleee
96k13133190
96k13133190
add a comment |
add a comment |
Globbing doesn't work that way unless you enable extglob shell opt. Instead, I recommend using find:
find . -maxdepth 1 -not -name '<NAME>' -or -name '<NAME>' -delete
before running this command with -delete ensure the output is correct
add a comment |
Globbing doesn't work that way unless you enable extglob shell opt. Instead, I recommend using find:
find . -maxdepth 1 -not -name '<NAME>' -or -name '<NAME>' -delete
before running this command with -delete ensure the output is correct
add a comment |
Globbing doesn't work that way unless you enable extglob shell opt. Instead, I recommend using find:
find . -maxdepth 1 -not -name '<NAME>' -or -name '<NAME>' -delete
before running this command with -delete ensure the output is correct
Globbing doesn't work that way unless you enable extglob shell opt. Instead, I recommend using find:
find . -maxdepth 1 -not -name '<NAME>' -or -name '<NAME>' -delete
before running this command with -delete ensure the output is correct
answered 16 hours ago
RafaelRafael
4,962102339
4,962102339
add a comment |
add a comment |
Method with default settings and no external procs:
for f in *; do [[ $f =~ ^file[12]$ ]] || echo "$f"; done
New contributor
vintnes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Method with default settings and no external procs:
for f in *; do [[ $f =~ ^file[12]$ ]] || echo "$f"; done
New contributor
vintnes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
Method with default settings and no external procs:
for f in *; do [[ $f =~ ^file[12]$ ]] || echo "$f"; done
New contributor
vintnes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Method with default settings and no external procs:
for f in *; do [[ $f =~ ^file[12]$ ]] || echo "$f"; done
New contributor
vintnes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 5 hours ago
New contributor
vintnes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered 16 hours ago
vintnesvintnes
765
765
New contributor
vintnes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
vintnes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
vintnes is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Ogden is a new contributor. Be nice, and check out our Code of Conduct.
Ogden is a new contributor. Be nice, and check out our Code of Conduct.
Ogden is a new contributor. Be nice, and check out our Code of Conduct.
Ogden is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f55546727%2fpattern-match-does-not-work-in-bash-script%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
Possible duplicate of How can I use inverse or negative wildcards when pattern matching in a unix/linux shell?, List all files that do not match pattern using ls, etc. And related is Why would I not leave extglob enabled in bash?
– jww
10 hours ago