Hello,
Sorry, I am a bit of list This command line works in a shell, but not in a bash I may miss some quotes ! Thanks for your help.
/usr/bin/rm -v !(ZMAT*|out*|Out*|GENBAS|Note*)
=========================================================================== Patrick DUPRÉ | | email: pdupre@gmx.com Laboratoire interdisciplinaire Carnot de Bourgogne 9 Avenue Alain Savary, BP 47870, 21078 DIJON Cedex FRANCE Tel: +33 (0)380395988 | | Room# D114A ===========================================================================
Patrick, The structure within the paren's looks like what would be used for a 'grep -Ev' to find everything BUT that mix of patterns. Can you explain what it is you are attempting to do, and provide some context, please. Thank you.-Joe
On Friday, June 4, 2021, 2:14:53 PM EDT, Patrick Dupre pdupre@gmx.com wrote:
Hello,
Sorry, I am a bit of list This command line works in a shell, but not in a bash I may miss some quotes ! Thanks for your help.
/usr/bin/rm -v !(ZMAT*|out*|Out*|GENBAS|Note*)
=========================================================================== Patrick DUPRÉ | | email: pdupre@gmx.com Laboratoire interdisciplinaire Carnot de Bourgogne 9 Avenue Alain Savary, BP 47870, 21078 DIJON Cedex FRANCE Tel: +33 (0)380395988 | | Room# D114A =========================================================================== _______________________________________________ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
I would have coded it this way: /usr/bin/rm -v `ls -1|egrep -ve '(^ZMAT|^out|^Out|^GENBAS|^Note)'`
And bash is a shell, but you mean a script. Likely in interactive bash the * are getting expanded so you might have to use noglob to suppress it or something similar.
Or you might have to use a single quote to suppress the expansion so that rm gets the *, otherwise the shell expands the * and rm gets a list of files.
[jwesterd@jwesterd-f33 aaa]$ ls -1 a b c d e f [jwesterd@jwesterd-f33 aaa]$ /usr/bin/rm -v !(a*|b*|c*|d*|e*) removed 'f' [jwesterd@jwesterd-f33 aaa]$ ls -1 a b c d e [jwesterd@jwesterd-f33 aaa]$ echo $0 bash
seems to work?
Are there asterisks or quotes in the files you are affecting?
Cheers
John Westerdale
Sr Container Consultant * RHCSA-8.2*
Red Hat https://www.redhat.com/ NYC Office/WFH
john.westerdale@redhat.com
M: 201-376-9993 IM: jwesterd He / Him / His https://www.redhat.com/
I respect your Life-Work balance.
No need to respond immediately if you receive this outside your normal working hours.
On Fri, Jun 4, 2021 at 2:27 PM Patrick Dupre pdupre@gmx.com wrote:
Hello,
Sorry, I am a bit of list This command line works in a shell, but not in a bash I may miss some quotes ! Thanks for your help.
/usr/bin/rm -v !(ZMAT*|out*|Out*|GENBAS|Note*)
=========================================================================== Patrick DUPRÉ | | email: pdupre@gmx.com Laboratoire interdisciplinaire Carnot de Bourgogne 9 Avenue Alain Savary, BP 47870, 21078 DIJON Cedex FRANCE Tel: +33 (0)380395988 | | Room# D114A =========================================================================== _______________________________________________ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
On 2021-06-04 12:04 p.m., Joe Zeff wrote:
On 6/4/21 12:21 PM, Joe Wulf via users wrote:
The structure within the paren's looks like what would be used for a 'grep -Ev' to find everything BUT that mix of patterns.
Checking with the man page, I find that -v stands for verbose, telling you what's happening.
Which man page? For grep, the "-v" is for inverting the result to only show non-matching lines.
Hello Joe,
On Fri, 4 Jun 2021 13:04:20 -0600 Joe Zeff joe@zeff.us wrote:
On 6/4/21 12:21 PM, Joe Wulf via users wrote:
The structure within the paren's looks like what would be used for a > 'grep -Ev' to find everything BUT that mix of patterns.
Checking with the man page, I find that -v stands for verbose, telling you what's happening.
-V, --version
-v, --invert-match
Regards,
Hi,
Patrick Dupre wrote:
Sorry, I am a bit of list This command line works in a shell, but not in a bash I may miss some quotes ! Thanks for your help.
/usr/bin/rm -v !(ZMAT*|out*|Out*|GENBAS|Note*)
The !(ZMAT*|...) syntax requires the bash extglob option. This must be explicitly enabled in a non-interactive session (like a script). For example:
#!/bin/bash
shopt -s extglob /usr/bin/rm -v !(ZMAT*|out*|Out*|GENBAS|Note*)
Fantastic, Thanks.
How can I leave this mode extglob ?
Patrick Dupre wrote:
Sorry, I am a bit of list This command line works in a shell, but not in a bash I may miss some quotes ! Thanks for your help.
/usr/bin/rm -v !(ZMAT*|out*|Out*|GENBAS|Note*)
The !(ZMAT*|...) syntax requires the bash extglob option. This must be explicitly enabled in a non-interactive session (like a script). For example:
#!/bin/bash shopt -s extglob /usr/bin/rm -v !(ZMAT*|out*|Out*|GENBAS|Note*)-- Todd _______________________________________________ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
On 2021-06-04 12:36 p.m., Joe Zeff wrote:
On 6/4/21 1:11 PM, Samuel Sieb wrote:
Which man page? For grep, the "-v" is for inverting the result to only show non-matching lines.
The man page for rm, of course. Why would I suggest that you look at any other command's man page to find out what an option for rm means?
You removed your text when quoting my email. In the email I replied to, you were quoting the grep line. No mention of rm at all.
Could you not simply \ escape the ! ?
On Fri, Jun 4, 2021, 3:05 PM Samuel Sieb samuel@sieb.net wrote:
On 2021-06-04 12:36 p.m., Joe Zeff wrote:
On 6/4/21 1:11 PM, Samuel Sieb wrote:
Which man page? For grep, the "-v" is for inverting the result to only show non-matching lines.
The man page for rm, of course. Why would I suggest that you look at any other command's man page to find out what an option for rm means?
You removed your text when quoting my email. In the email I replied to, you were quoting the grep line. No mention of rm at all. _______________________________________________ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
Samuel Sieb wrote:
On 2021-06-04 1:00 p.m., Patrick Dupre wrote:
How can I leave this mode extglob ?
Do you need to? It will only apply to the rest of the script anyway.
True.
Though depending on the size of the script and what else it does, there are certainly times when you don't want this enabled for the entire script.
There are a few ways to handle that.
You can simply unset it via `shopt -u extglob` after the rm.
Another common method to set an option and only have it effect a small portion of the code is to use a subshell. Like:
#!/bin/bash
# some code
( shopt -s extglob rm -v !(...) )
# some other code
The subshell ensures that the shopt is only in effect for the commands run within the opening and closing parentheses.
There are, as alway, pros and cons to each method. With the subshell method, a potential con is that the environment might differ from the rest of the script. If you depend on variables which are set earlier in the script you just need to be sure they're available to you in the subshell. Similarly, if you set a variable in the subshell it won't be available outside of the subshell.
On Fri, Jun 04, 2021 at 10:00:17PM +0200, Patrick Dupre wrote:
Patrick Dupre wrote:
Sorry, I am a bit of list This command line works in a shell, but not in a bash I may miss some quotes ! Thanks for your help.
/usr/bin/rm -v !(ZMAT*|out*|Out*|GENBAS|Note*)
The !(ZMAT*|...) syntax requires the bash extglob option. This must be explicitly enabled in a non-interactive session (like a script). For example:
#!/bin/bash shopt -s extglob /usr/bin/rm -v !(ZMAT*|out*|Out*|GENBAS|Note*)Fantastic, Thanks.
How can I leave this mode extglob ?
Well you might wonder why Todd used the "-s" option for shopt. That is to "enable" or "set" the option to on.
Likely a manpage peek would show an option to turn off extglob. Hint, it is probably "disable" or "unset".
Joe Zeff wrote:
On 6/4/21 2:05 PM, Samuel Sieb wrote:
You removed your text when quoting my email. In the email I replied to, you were quoting the grep line. No mention of rm at all.
We were, and are discussing the way rm acts in a shell script, so I expected that rm was the implied command.
I don't think that's entirely accurate. :)
You quoted the portion which had `grep -Ev` in your reply:
On 6/4/21 12:21 PM, Joe Wulf via users wrote: > The structure within the paren's looks like what would be used for a 'grep > -Ev' to find everything BUT that mix of patterns.
Checking with the man page, I find that -v stands for verbose, telling you what's happening.
So Joe Wulf is explicitly talking about the -v option to grep and your reply suggests that -v means verbose -- without any mention that you are referring to rm.
Within your own context that might have made perfect sense, but I hope you can see how it's certainly not as clear to others reading the various sub-threads in this topic. :)
Anyway, all of that was a distraction from the issue at hand, which was the difference between interactive use with extglob and non-interactive use without it.