Re: bash command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

-- 
Todd

Attachment: signature.asc
Description: PGP signature

_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
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@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux