4 ms·
One of the reasons I like zsh is its copious expansion flags. If you aren't wedded to POSIX or bash syntax, consider zsh for this reason alone. In the case of
by Adaptive 12y ago
One of the reasons I like zsh is its copious expansion flags. If you aren't wedded to POSIX or bash syntax, consider zsh for this reason alone.
In the case of the first example he shows, the cat -n problem, you can do the following in zsh to expand the results of the wildcard globbing automatically:
cat *(:A)
This will give cat full paths. Not significantly different from the PWD referenced with ./* in his example, but more universal in applicability, particularly when you start to use things like the file type filters:
cat *(.:A)
giving you only files, not directories, and also expanding to absolute paths, while
cat **/*(.:A)
does the same for plain files in the working directory and all subdirectories as well.
Remember to test your patterns with a print statement first:
print -l **/*(.:A)
before passing them to a command.
- sjolsen 12y ago>Remember to test your patterns with a print statement first ZSH has an option to expand globs onto the command line the first time you hit return, and issue the command the second. I don't remember what it is.
- Adaptive 12y agoBy default zsh will expand globs if you hit tab on the command line. However if you have more than a handful of matches it's going to be a suboptimal method of eyeballing the glob results. I prefer to use `print -l` as it will break the glob results on separate lines. An additional benefit of ZSH is that it will normally return each glob result as an independent item (this avoids the problem bash has with just returning strings that in turn are broken on IFS characters). Using that flag with print will give you a clear sense of the actual results.
- Apofis 12y agoWhat about fish?