Wednesday, May 8, 2024
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 653  / 1 Year ago, mon, february 6, 2023, 5:24:27

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?


More From » command-line

 Answers
0

Here's what happens



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.



Solution: escape or quote it!



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.



Demo



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.

[#30576] Tuesday, February 7, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
antoccasiona

Total Points: 430
Total Questions: 127
Total Answers: 131

Location: Netherlands
Member since Sat, Jun 26, 2021
3 Years ago
antoccasiona questions
Sat, Oct 23, 21, 22:34, 3 Years ago
Sat, Sep 24, 22, 09:39, 2 Years ago
Sun, Jan 15, 23, 11:08, 1 Year ago
;