Sujet : Re: (shellcheck) SC2103
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shellDate : 06. Mar 2025, 12:32:28
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vqc14c$881$1@news.xmission.com>
References : 1 2
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
83v7snfkm5.fsf@helmutwaitzmann.news.arcor.de>,
Helmut Waitzmann <
oe.throttle@xoxy.net> wrote:
...
Does
>
>
cd -- somedir &&
{
do_something
cd ..
}
>
>
make shellcheck happy while at the same time localizing the
damage and avoiding a subshell?
Yes, it does - silence both warnings. But seems kind of end-around.
The point is that it should recognize that you are running in "trap ... ERR"
mode and therefore there can't be an untrapped "cd".
Now, I get that this is probably just too hard for shellcheck to do
(although it is amazing it does as much as it does, and it is getting
better with each new version), and so we have to live with the warning, but
my overall point is that this could be problematic if you happen to work in
an environment where management insists that your script pass shellcheck.
cd somewhere;...;cd -
>
But note that "cd -" - even in a script - prints the name of the directory
it is cd'ing back to, which is annoying. I could not find any option to
turn this off,
>
>
cd -- "$OLDPWD"
>
Will help.
Pick your poison.
I'm happy enough with just using "> /dev/null".
It is about the same # of characters to type.
-- Nov 4, 2008 - the day when everything went from being Clinton's fault to being Obama's fault.