Discussion:
bash command
Patrick Dupre
2021-06-04 18:14:22 UTC
Permalink
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: ***@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 -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: https://pagure.io/fedora-in
Joe Wulf via users
2021-06-04 18:21:22 UTC
Permalink
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 <***@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: ***@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 -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
Roger Heflin
2021-06-04 18:35:09 UTC
Permalink
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.
Joe Zeff
2021-06-04 19:04:20 UTC
Permalink
Post by Joe Wulf via users
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.
_______________________________________________
users mailing list -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: htt
Samuel Sieb
2021-06-04 19:11:03 UTC
Permalink
Post by Joe Zeff
Post by Joe Wulf via users
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.
_______________________________________________
users mailing list -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: https://pagure.io/f
Joe Zeff
2021-06-04 19:36:58 UTC
Permalink
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?
_______________________________________________
users mailing list -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list
Samuel Sieb
2021-06-04 20:05:27 UTC
Permalink
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 -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: https://pagure.io/fedora-
kevin martin
2021-06-04 20:07:50 UTC
Permalink
Could you not simply \ escape the ! ?
Post by Samuel Sieb
Post by Joe Zeff
Post by Samuel Sieb
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.
_______________________________________________
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
https://pagure.io/fedora-infrastructure
Joe Zeff
2021-06-04 20:29:15 UTC
Permalink
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.
_______________________________________________
users mailing list -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
Todd Zullinger
2021-06-04 20:40:28 UTC
Permalink
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. :)
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.
--
Todd
wwp
2021-06-04 19:17:51 UTC
Permalink
Hello Joe,
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,
--
wwp
https://useplaintext.email/
Joe Zeff
2021-06-04 19:37:40 UTC
Permalink
Post by wwp
-V, --version
-v, --invert-match
Yes, that's true for grep, but we're discussing rm here.
_______________________________________________
users mailing list -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: https://pagure.i
John Westerdale
2021-06-04 18:42:11 UTC
Permalink
[***@jwesterd-f33 aaa]$ ls -1
a
b
c
d
e
f
[***@jwesterd-f33 aaa]$ /usr/bin/rm -v !(a*|b*|c*|d*|e*)
removed 'f'
[***@jwesterd-f33 aaa]$ ls -1
a
b
c
d
e
[***@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

***@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.
Post by Patrick Dupre
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*)
===========================================================================
Laboratoire interdisciplinaire Carnot de Bourgogne
9 Avenue Alain Savary, BP 47870, 21078 DIJON Cedex FRANCE
Tel: +33 (0)380395988 | | Room# D114A
===========================================================================
_______________________________________________
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
https://pagure.io/fedora-infrastructure
Patrick Dupre
2021-06-04 19:36:19 UTC
Permalink
_______________________________________________
users mailing list -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
Todd Zullinger
2021-06-04 19:46:34 UTC
Permalink
Hi,
Post by Patrick Dupre
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
Patrick Dupre
2021-06-04 20:00:17 UTC
Permalink
Fantastic,
Thanks.

How can I leave this mode extglob ?
Post by Todd Zullinger
Post by Patrick Dupre
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
#!/bin/bash
shopt -s extglob
/usr/bin/rm -v !(ZMAT*|out*|Out*|GENBAS|Note*)
--
Todd
_______________________________________________
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
_______________________________________________
users mailing list -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastru
Samuel Sieb
2021-06-04 20:07:04 UTC
Permalink
Post by Patrick Dupre
How can I leave this mode extglob ?
Do you need to? It will only apply to the rest of the script anyway.
_______________________________________________
users mailing list -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: https:/
Todd Zullinger
2021-06-04 20:28:06 UTC
Permalink
Post by Samuel Sieb
Post by Patrick Dupre
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.
--
Todd
Jon LaBadie
2021-06-04 20:31:33 UTC
Permalink
Post by Patrick Dupre
Post by Todd Zullinger
Post by Patrick Dupre
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
#!/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".

--
Jon H. LaBadie ***@jgcomp.com
_______________________________________________
users mailing list -- ***@lists.fedoraproject.org
To unsubscribe send an email to users-***@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/***@lists.fedoraproject.org
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastru
Loading...