ramble
asked on
Basic piping | question maybe?
I'd like to change to the directory automatically from the output of the which command.
Example:
$ pwd
/user/home/Ramble
$ which ls
/bin/ls
$ cd /bin
Is there a way to combined the last 2 commands (efficiently) like:
$which ls | cd
Example:
$ pwd
/user/home/Ramble
$ which ls
/bin/ls
$ cd /bin
Is there a way to combined the last 2 commands (efficiently) like:
$which ls | cd
ASKER
Your command works in csh too.
Ok...that works. But I'd still like it to be as "efficient" as just:
which ls
cd /bin
Ofcouse, the longer the directory, the more efficient your command seems to be :^)
A more general "modification" of my original question...
How could I take the output of a command, and use it as the input of another....like:
find . -print | grep -i \\.pl | grep -v \\.pl\\/ | cat <each line of the output>
or
ps -ef | grep -i aprocess | awk '{print $2}' | kill -9 <the process ID that was outputted>
or
which uname | ls -ls <uname file result>
or...well, you get the picture...right? The last command would have to work on each individual line of the last outputted command. Anyway, this is probably beyond the scope (although somewhat related) of the original question, and ofcourse, points will be adjusted. But as I started thinking about it...I thought it'd be something cool to be able to do :^)
Ok...that works. But I'd still like it to be as "efficient" as just:
which ls
cd /bin
Ofcouse, the longer the directory, the more efficient your command seems to be :^)
A more general "modification" of my original question...
How could I take the output of a command, and use it as the input of another....like:
find . -print | grep -i \\.pl | grep -v \\.pl\\/ | cat <each line of the output>
or
ps -ef | grep -i aprocess | awk '{print $2}' | kill -9 <the process ID that was outputted>
or
which uname | ls -ls <uname file result>
or...well, you get the picture...right? The last command would have to work on each individual line of the last outputted command. Anyway, this is probably beyond the scope (although somewhat related) of the original question, and ofcourse, points will be adjusted. But as I started thinking about it...I thought it'd be something cool to be able to do :^)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cool! Thanks
my pleasure.
happy scripting!!!
happy scripting!!!
ASKER
Thanks_ramble
ASKER
Thanks_ramble
Just Ignore the last comment
Just Ignore the last comment
This will do it for you. It works in Bourne, Korn and bash shells.
cd `dirname \`which ls\` `
Regards, Nisus
http://www.omnimodo.com