Home > Mobile >  ZSH is set up to use aliases, but now the script I run does not honor them
ZSH is set up to use aliases, but now the script I run does not honor them

Time:07-22

Running zsh locally and installed oh-my-zsh.

~/.zprofile:

# Added by Toolbox App
export PATH="$PATH:/Users/boxcee/Library/Application Support/JetBrains/Toolbox/scripts"

# Github
export GITHUB_TOKEN=xxx

# Homebrew
eval "$(/opt/homebrew/bin/brew shellenv)"

~/.zshrc:

# Podman
alias docker=podman
alias docker-compose=podman-compose

# Python
alias python=python3
alias pip=pip3

Now I am trying to run the following script:

#!/usr/bin/env zsh

docker version

and get this error:

./test.sh:3: command not found: docker

I don't understand why I get it. Running the command separately in my ZSH works just fine.

CodePudding user response:

If you run your script as an executable, it runs in a subshell. Since aliases are not exported to the environment, the subshell cannot import them. If you want aliases to be retained, then you should source your script instead, which causes it to run in the same shell from which you call it.

  • Related