Now I try to create an alias for this command:
alias cdport 'cd `whereis \!^ | awk \'{print $2}\'`'
Can't find any good examples of using more than 2 commands in a sequence.
How to fix that code? Thanks.
You can't escape quotes in strings in csh. You need to switch to double-quoted strings to enter those characters:
alias cdport 'cd `whereis \!^ | awk '"'"'{sub("/[^/]*$", "/", $2); print $2}'"'"'`'
I've also fixed the awk
script to remove the filename from the output of whereis
, so you just get the directory part.
whereis find
looks like find: /usr/bin/find /usr/share/man/man1/find.1.gz
, so $2
would be /usr/bin/find
. cd
needs a directory, so it should be cd /usr/bin
.
$2
to get a directory that you cancd
to.