Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VIRTUAL_ENV="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )" evquivalent in zsh/fish/csh/Xonsh

89 views
Skip to first unread message

Hongyi Zhao

unread,
Dec 31, 2019, 8:11:52 PM12/31/19
to
Hi,

I'm trying use this tool https://pypi.org/project/virtualenv-relocate to
deal with on virtualenv for letting it relocatable.

This tool in fact do the following replacement on the corresponding
script file:

Search for:
pattern = r'^VIRTUAL_ENV=".*?"$'

replaced to:
replacement = 'VIRTUAL_ENV="$( cd "$( dirname "$
{BASH_SOURCE[0]}" )/.." && pwd )"'


But it only valid for bash, I also want to do the corresponding
replacement for zsh/fish/csh/Xonsh. How should adapt the replacement
expression for my case?

Regards

Stephane Chazelas

unread,
Jan 1, 2020, 6:00:17 AM1/1/20
to
2020-01-01 01:11:49 +0000, Hongyi Zhao:
[...]
> replacement = 'VIRTUAL_ENV="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"'
>
>
> But it only valid for bash, I also want to do the corresponding
> replacement for zsh/fish/csh/Xonsh. How should adapt the replacement
> expression for my case?
[...]

The zsh "equivalent" of bash's

VIRTUAL_ENV="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"

Which AFAICT is meant to get you the path of the parent
directory of the script's parent directory

Would be something like:

VIRTUAL_ENV=$0:a:h:h

See also $0:P:h:h where $P is the "realpath" (canonical absolute
path) of $0.

--
Stephane
0 new messages