> for f in `perl -e '$, = " "; print split /:/, $ENV{PATH};'`; do find $f | grep 'somecmd'; done
In other news, for those of you for whom the above is not complete gibberish. There has got to be a better way to do this. All I am trying to do is find all the commands in my path with a certain substring. One might think this would be a job for
(
Read more... )
Well, actually only 1 character too short. Replace ls with find, but then replace "' '" with "\ "...
for d in `echo $PATH | tr : \ `; do find $d | grep 'somecmd'; done [66 chars]
But really, must we use echo and tr to extract the paths in $PATH (and waste 10 characters)? No!
for d in ${PATH//:/ }; do find $d | grep 'somecmd'; done [56 chars]
But there are shorter solutions yet! To start, there's inferno0069's solution, which can have the variable dir trimmed to d to get it to...
zsh -c 'for d in $path; find $d | grep "somecmd"' [49 chars]
Can this be beat? If you don't mind running the command as root, or ignoring the "Permission denied" errors on stderr, we can just let find search the whole filesystem!
find / -regex "^\(${PATH//:/\|}\)/.*somecmd.*" [46 chars]
And that's as small as I've gotten, unless you resort to removing whitespace as if you were trying to fail CS 70. Then, replace "-regex" with "| grep" (same number of characters), and then you can trim off two pesky spaces.
find /|grep "^\(${PATH//:/\|}\)/.*somecmd.*" [44 chars]
And that's as far as I could shrink things down.
Sadly, locate only seems to use basic regular expressions, and thus doesn't support alternations. But if it did, and if you didn't mind your results being slightly out of date, we could take advantage of the fact that "find /" and "locate" are the same length, but locate uses -r rather than -regex for regular expressions to bring things down even further. Sadly, it doesn't work.
locate -r "^\(${PATH//:/\|}\)/.*somecmd.*" [42 chars]
And although other solutions are shorter, I found this solution rather pleasing.
sh -Oc nullglob "echo {${PATH//:/,}}/*somecmd*" | tr \ \\n [59 chars]
Reply
Umm ... yes ... well done! I hereby proclaim you champion of obscure shell syntax. Let the heralds be sent forth to the four corners of this LJ, proclaiming Jibb to be the one true master of completely arcane and incomprehensible shell expressions. Truly it is he who is understood by the shell and no one else!
(parse that last line as you will)
Reply
Reply
And on a largely unrelated note, I finally finished that black roof climb at Hangar 18 that you introduced me to. So fun!
Reply
At any rate, well done you. I know I was quite please (and sore!) the first time that I managed that climb. I was surprised at how technically easy it is. The tough things about it turn out to be the mad arm endurance required and the sheer terror of climbing along upside-down for 30 ft or so. Actually, the latter was the real sticking point with me. For the longest time I had the strength and endurance but just couldn't bring myself to do it. Actually, the day I ended up completing the roof, I was pretty sleep-depped and probably not thinking very clearly.
Reply
Reply
for d in $path;find $d|grep "somecmd" [37 chars]
Reply
Leave a comment