0

I'm facing an issue while trying to use alias in my zsh

If I run alias , I get a list of all my alias, the ones in .aliases file, and the ones that I run manually in zsh:

oloco@Arch: alias

my_manual_alias='yes'
cat='bat --paging=never -l log'
cp='cp -iv'
doc=/home/oloco/Documents
dot=/home/oloco/.dotfiles
dow=/home/oloco/Downloads
egrep='egrep --color=auto'
fgrep='fgrep --color=auto'

But, I I try to echo any of them, nothing is shown:

oloco@Arch: echo $my_manual_alias

Why this behaviour? I think I should get my alias this way...or maybe not?

Thank you in advance!

  • An alias can only occur as the first word in a command, so `echo $my_manual_alias` will never work. If you want to see all your aliases together, what about simply `alias`? If you want to print your aliases when you invoke them, or save the full version in shell history, there are a lot of questions on here about exactly that. – Josh Friedlander Jul 31 '22 at 11:30
  • Hi @JoshFriedlander, thank you very much for your answer. I'm used to work with bash, so echo $myalias is the way Im used to. when you say " If you want to print your aliases when you invoke them, or save the full version in shell history, there are a lot of questions on here about exactly that.", what do you mean? I'm sorry for my poor english. I found a way to "echo" my alias, by using `alias myalias` . Is this the correct way to do it? Again, thank you very much for your answer – FueraDeServicio Jul 31 '22 at 12:07
  • Yeah, I think that's the correct way to do it. To clarify, I meant that if whenever you use an alias you want zsh to print it, there are questions here such as [this](https://stackoverflow.com/questions/9299402/echo-all-aliases-in-zsh) and [this](https://stackoverflow.com/questions/18143307/print-executed-alias-in-zsh-or-bash) that help with that. – Josh Friedlander Jul 31 '22 at 13:20
  • `echo $my_manual_alias` outputs the content of the variable `my_manual_alias`. If you never set this variable, you don't get an output. I suggest that you do a `set -u` in the future to catch this kind of error. – user1934428 Aug 04 '22 at 10:23
  • To see the content of an alias, the command would be `type my_manual_alias`. – user1934428 Aug 04 '22 at 10:24

0 Answers0