[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Quiet version of pushd/popd
From: |
Andreas Kusalananda Kähäri |
Subject: |
Re: Quiet version of pushd/popd |
Date: |
Wed, 21 Apr 2021 20:47:11 +0200 |
On Wed, Apr 21, 2021 at 01:13:20PM -0500, John Hanks wrote:
> Hi,
>
> It's always been a mystery to me why pushd/popd don't have a -q option to
> silence output. I tend to use them like:
>
> pushd /path/to/go/to > /dev/null 2>&1
> code for this spot
> pushd /other/path/to/go/to > /dev/null 2>&1
> code for this spot
> popd > /dev/null 2>&1
> popd > /dev/null 2>&1
>
> With the indention in my scripts making visual blocks to distinguish what
> location is "active".
>
> Is there a shorter?, more concise?, better?, easier?, recommended? way to
> get these to work silently? Also just curious what the reasoning is for why
> there isn't a flag to make them silent. This works fine for me now, it's
> just not very nice to look at and my best idea has been to make
> functions my_pushd and my_popd which wrap them and silence the output, but
> really not fond of the name change when doing that.
>
> Best,
>
> griznog
I didn't grow up with popd and pushd and I don't really see what they
offer that cd isn't doing for me (I've never learnt to work with
a directory stack, and that's not how I see myself navigating the
filesystem). They seem mostly useful for command line work, not for
scripts.
In scripts, I would use
( cd /path/to/go/to || exit 1
# code for this spot
( cd /other/path/to/go/to || exit 1
# code for this spot
)
)
Each (...) subshell would have its own working directory, set by the
initial cd. The changing of the working directory of a subshell is not
visible to the parent subshell.
--
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden
.