Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aliases doesn't work when explicitly invoked as bash #115

Closed
eshepelyuk opened this issue May 17, 2024 · 6 comments
Closed

Aliases doesn't work when explicitly invoked as bash #115

eshepelyuk opened this issue May 17, 2024 · 6 comments

Comments

@eshepelyuk
Copy link

eshepelyuk commented May 17, 2024

Hello @sachaos

I've followed this comment to test alias support in bash. And my minimal .profile looks like

if [ -f "/home/linuxbrew/.linuxbrew/bin/brew" ]; then
    eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
alias k='kubectl'

When I try to call viddy in interactive shell like following

viddy --shell sh --shell-options "-l" k get all

the alias works. But when I invoke it as a bash

viddy --shell bash --shell-options "-l" k get all

I'm getting this error
image

Environment

$ uname -srvmpio
Linux 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS"
$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
@sachaos
Copy link
Owner

sachaos commented May 17, 2024

@eshepelyuk Hi. Thank you for using this tool.
Do you have ~/.bash_profile or ~/.bash_login?

After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

https://linux.die.net/man/1/bash

@eshepelyuk
Copy link
Author

@eshepelyuk Hi. Thank you for using this tool.
Do you have ~/.bash_profile or ~/.bash_login?

After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

https://linux.die.net/man/1/bash

i only have ~/.profile

@sachaos
Copy link
Owner

sachaos commented May 17, 2024

@eshepelyuk
Thank you. I could reproduce the problem.
I found the solution.
Please try with the -i option (viddy --shell bash --shell-options "-li" k get all).

We are running the command in viddy with the -c option (bash -c "k get all").
However, aliases are not expanded in bash non-interactive mode.
So, we should set bash to interactive mode to expand aliases.

Alternatively, if you set shopt -s expand_aliases in .profile, that would work as well.

@eshepelyuk
Copy link
Author

eshepelyuk commented May 17, 2024

@eshepelyuk
Thank you. I could reproduce the problem.
I found the solution.
Please try with the -i option (viddy --shell bash --shell-options "-li" k get all).

We are running the command in viddy with the -c option (bash -c "k get all").
However, aliases are not expanded in bash non-interactive mode.
So, we should set bash to interactive mode to expand aliases.

Alternatively, if you set shopt -s expand_aliases in .profile, that would work as well.

Ahh, so bash doesn't expand aliases in non-interactive mode, but [da]sh does, right?

@sachaos
Copy link
Owner

sachaos commented May 17, 2024

@eshepelyuk Yes, I think so.

@eshepelyuk
Copy link
Author

@eshepelyuk Yes, I think so.

thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants