I ran the following command on zsh
sudo apt-get install rhythmbox*
It produced an error, when I ran the same command in bash it worked. Why does this happen?
How can I make the above command work on zsh?
I ran the following command on zsh
sudo apt-get install rhythmbox*
It produced an error, when I ran the same command in bash it worked. Why does this happen?
How can I make the above command work on zsh?
Bash will try to evaluate the pattern rhythmbox*
on the current working directory. As it is very unlikely there will be any file or directory starting with the sequence of rhythmbox
, it will not expand, but Bash will provide it as an argument to apt-get
here.
Note that if you have a file there with the name rhythmbox-test
then it won't work as it will be expanded and rhythmbox-test
will be provided as the argument to apt-get
.
So, to reliably use the patters in apt-get
in a Bash shell, you should always escape it. Use quotes or the backslash, e.g.
sudo apt-get install rhythmbox*
or
sudo apt-get install "rhythmbox*"
About the same goes for zsh.
The expansion of the pattern is called globbing.
touch aa ab # creates files aa and ab
ls a* # lists both files as Bash provided ls two arguments.
ls 'a*' # No such file or directory. Bash provided literally a* to ls.
ls a* # No such file or directory. Same as above.