I use zsh in centos. And I want running some shell script. Like this.



# something ..

source ./aliases-file.sh


alias test=ls
alias test2=cat

I run ./script.sh, the alias has not been applied to the current session. how can I work this?

  • The source statement goes before the # something. – suspectus Aug 16 '17 at 14:30
  • I tried, but it did not matter. – Junsu Kim Aug 16 '17 at 14:43

When you run script.sh it is executed in a subshell and your aliases won't propagate up to the calling shell (or current session as you refer to it). You need to source script.sh itself: source script.sh. That will cause the commands to be run in your current shell and the aliases will become visible.

Side note: for portability reasons you should consider using . instead of source as the former is POSIX standard while the latter is a bashism.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.