Re: (shellcheck) SC2103

Liste des GroupesRevenir à cu shell 
Sujet : Re: (shellcheck) SC2103
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shell
Date : 06. Mar 2025, 12:39:35
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vqc1hn$881$2@news.xmission.com>
References : 1 2
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <20250305103210.358@kylheku.com>,
Kaz Kylheku  <643-408-1753@kylheku.com> wrote:
On 2025-03-05, Kenny McCormack <gazelle@shell.xmission.com> wrote:
All testing done with shellcheck version 0.10.0 and bash under Linux.
>
Shellcheck says that you should replace code like:
>
    cd somedir
    do_something
    cd .. # (Or, cd -, which is almost, but not exactly the same thing)
>
with
>
    (
    cd somedir
    do_something
    )
>
That obviously won't work if do_something has to set a variable
that is then visible to the rest of the script.

That's actually mentioned in the rationale on the web page.
That if you need to set a variable, you can't use subshells.

Forking a process just to preserve a current working directory
is wasteful; we wouldn't do that in a C program, where we might
open the current directory to be saved, and then fchdir back to it.
>
However, most of the actions in a shell script fork and exec
something anyway.

Yes, but those would be the cheap form of fork(), where if it is quickly
followed by an exec(), you don't have to do COW.

Note that, in Linux, fork() is actually an alias for vfork().

--
The randomly chosen signature file that would have appeared here is more than 4
lines long.  As such, it violates one or more Usenet RFCs.  In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/TedCruz

Date Sujet#  Auteur
5 Mar 25 * (shellcheck) SC21038Kenny McCormack
5 Mar 25 +* Re: (shellcheck) SC21032Helmut Waitzmann
6 Mar 25 i`- Re: (shellcheck) SC21031Kenny McCormack
5 Mar 25 `* Re: (shellcheck) SC21035Kaz Kylheku
5 Mar 25  +- Re: (shellcheck) SC21031Janis Papanagnou
5 Mar 25  +- Re: (shellcheck) SC21031Helmut Waitzmann
6 Mar 25  `* Re: (shellcheck) SC21032Kenny McCormack
6 Mar 25   `- Re: (shellcheck) SC21031Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal