Code Review Asked on November 21, 2021
My target is to have an environment variable being set to a leading substring of $PWD
and to be unset when $PWD
does not start with that substring.
So I decided to override cd
like this (here I’m assuming the substring is just my home directory /home/enrico
, but in general is fine for me that it be an hardcoded regex):
cd() {
command cd "$@"
export MYVARIABLE=$(<<< $PWD sed -E 's!(/home/enrico)(/?$|.*)!1!')
if [[ $MYVARIABLE == $PWD ]]; then
unset MYVARIABLE
fi
}
This seems to work fine, but I’d like to have some different point of view on it.
(Btw, if there are appropriate tags to add, please do, as I haven’t found any more than bash
.)
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP