0

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.

2
  • Your general syntax looks correct. But you need to remove the filename from $2 to get a directory that you can cd to.
    – Barmar
    Commented Nov 17, 2014 at 21:56
  • @Barmar it returns "Unmatched `." after "source .cshrc"
    – kAldown
    Commented Nov 17, 2014 at 23:27

1 Answer 1

0

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.

2
  • Actually I put awk only for removing filename. I thought that print $2 (second column) from first command output is right scenario.
    – kAldown
    Commented Nov 18, 2014 at 11:55
  • On my Debian system, the output of 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.
    – Barmar
    Commented Nov 18, 2014 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .