Fix the script when sourced from zsh#208
Conversation
|
this looks like it might now work in bash? |
I tested it in both bash and zsh, both when sourced or executed directly (however don't see the use case for the latter one). Also ran ./configure with sources novarc and haven't noticed any issues |
|
There are a number of differences between zsh and bash. So it's going to be difficult for a script to work in both shells. A simple workaround is (assuming user starts in zsh): If that's not acceptable, and zsh support is absolutely required, perhaps we can make two: |
IMHO only the changes I am proposing in the PR are needed to make it work on both bash and zsh. I have tested this for both shells and haven't noticed problems but if more testing is needed I am happy to do that. |
I don't see any issues - just saying that keeping script written in X working in Y is always going to be hard when X & Y aren't feature compatible. If we go with the PR as is, a comment might be useful so that future travellers know they should keep it compatible with zsh.
That shouldn't be an issue as every script that sources it is a bash script. The only issue here is that sourcing Alternatively, novarc can be modified to produce those variables and that can be sourced in any shell. Example: |
|
Hi @pponnuvel I got your point about the need to maintain the script for both shells. I have added the comment as you suggested. |
|
Thanks @wilkmar . Yes, it makes sense to change the shebang in There's also one more in |
the |
Regardless, you can change the shebang in both. |
|
ACK but rather I will make it a separate PR |
|
Created PR #209 |
openstack/novarc
Outdated
| scriptdir=$(readlink --canonicalize $(dirname ${BASH_SOURCE[0]-$0})) | ||
|
|
||
| # cache juju status | ||
| juju status --format=json > $juju_status_json_cache |
There was a problem hiding this comment.
I have noclobber set in my zsh config so this line fails for me since mktemp has already created the file. If Ichange the redirection to >| instead of > i.e.
juju status --format=json >| $juju_status_json_cache
everything works fine in both bash and zsh.
|
I've been using this on top of the main branch for a few weeks without issue. Any chance we could get it merged? |
|
I rebased this branch onto main. It would be awesome if someone could merge it. |
|
Hi @wilkmar ! Could you rebase (again, sorry). Thanks! |
|
Hey @nicolasbock , I just did. Please have a look whenever you are available. Thx! |
When the novarc file is sourced from the Zsh, it fails due to a few Bash specifics: - $BASH_SOURCE - does not exist in Zsh - readarray - does not exist in Zsh Resolves issue canonical#176 Signed-off-by: Marcin Wilk <marcin.wilk@canonical.com>
|
@nicolasbock discussed it with @raineszm |
When the novarc file is sourced from the Zsh, it fails due to a few Bash specifics:
Resolves issue #176