Closed derick closed 7 years ago
Help me understand the problem? I can't see it in the code you've put here. Bash (the shell) and Bash the "language" are not the same thing - Z shell uses bash (the language) so whatever you write should be the same... I think...
So what's the problem?
I don't believe it's correct to say that "Z shell uses bash (the language)". Zsh and Bash are two independently implemented shells which happen to behave the same way in a lot of cases (by design) when you give the same input to each shell, just like some typical programming languages are designed to treat various code in the same way as each other (but it would not be correct, for example, to state that "Python (the interpreter) uses Ruby (the language)" just because they treat the input 4 + 3
(and much more than that) in the same way).
The issue in this particular instance is is that Bash (and probably a number of other shells) don't treat the relevant input in the same way as Zsh. Bash did not implement the necessary **/*
globbing feature until Bash 4.0 (which is not present on macOS, for instance, which ships with Bash 3.2). And even in Bash 4.0, this feature is off by default.
If @derick runs ls **/*.jpg
in Bash, he would see ls: **/*.jpg: No such file or directory
because Bash is not doing the necessary expansion. If he gives the same command to Zsh, however, the glob works as intended, and many matching files are displayed. (I shortened his command for the sake of this explanation).
In a Bash (4.0+) shell, type shopt globstar
and you should get globstar off
. Try the ls **/*.jpg
command (or something similar) in an appropriate folder and see what happens. Then turn the globbing feature on with shopt -s globstar
(verify that it's now on, with shopt globstar
) and try again.
Speaking of this, in 15.2.1, you state "This line right here says “list out the jpg and png files, any name, any directory”." Perhaps it is worth clarifying that it is not any directory that is searched, but only the working directory and its subdirectories?
Fair enough. There is no "Bash standard" so sure, there will be differences. I think it's more confusing to parse this deeper and say "Z-shell script which looks mostly like Bash script" don't you think?
The problem, as I'm understanding it, is that globbing doesn't work in bash the way it does in Z-shell (and some other variances). The fix, then, would be to mention "I'm using Z-shell so I can glob easier" or some such?
RE the working vs. any directory... I think that's fairly obvious.
I agree, a mention that the reader would have to use Zsh to be able to do some of the things you're doing with the same efficiency/in the exact same way (or something along those lines) sounds reasonable. Also fair enough about the working directory thing, the context does make it more clear than I perhaps had thought before.
I added some clarifications so closing for now.
It's implied that we're still using Bash, though the description for your results graphic mentions you're using Zsh. However, I believe it's necessary to change to Zsh to get this command to work as evidenced by these results: