|
|
|
|
|
by arp242
805 days ago
|
|
Languages like Ruby, Perl, and PHP have a backtick that can be used for that; for example in Ruby: >> files = `ls / | grep ^b`.split("\n")
=> ["bin", "books", "boot"]
>> p $?
#<Process::Status: pid 10889 exit 0>
>> `false`
=> ""
>> p $?
#<Process::Status: pid 10898 exit 1>
I don't use it a lot because I don't feel like installing Ruby just for a few scripts, and zsh solves enough of the problems for me anyway.Also parsing ls output isn't necessarily a good idea, and what you really miss is "first class globbing" like: for f in /b*; [..]
arr=(/b*)
|
|
Thinking about it, this doesn't need to be an operator, and i could probably just write this myself and start trying it.
Interesting point about globbing. My feeling is that i don't actually use it a lot in scripts - the criteria for matching are usually complicated enough that i'm much more likely to use find. In a project with 1376 non-comment lines of shell script, i found eleven uses of globbing.