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@lists.fedoraproject.org
To unsubscribe send an email to users-le...@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

Reply via email to