sachaos/viddy

Aliases doesn't work when explicitly invoked as bash

eshepelyuk opened this issue · 6 comments

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)

@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 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

@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
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?

@eshepelyuk Yes, I think so.

@eshepelyuk Yes, I think so.

thanks for the explanation.