> 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... )
Comments 14
Reply
Actually, it is, by two characters. Your change uses ls which only will return the name of the actual command, but I want the full path, which find so conveniently provides.
Er ... well done, ol' bean!
Reply
Reply
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]
( ... )
Reply
Reply
Reply
Reply
Reply
Leave a comment