1

I made a simple example for this question. I can do

ckim@stph45:~] echo 1 2 3 | awk '{print $2}'
2

I wanted to make an alias for this whole command but it gives em an error (I'm using csh)

ckim@stph45:~] alias tt 'echo 1 2 3 | awk '{print $2}''
Missing }.

How do I escape '? I tried

alias tt 'echo 1 2 3 | awk \'{print $2}\''
alias tt 'echo 1 2 3 | awk "'{print $2}'"'

But didn't work. => solved. Please 'ADD' below.

ADD : as l|L|l's commend below, I can pass it by `alias tt "echo 1 2 3 | awk '{print $2}'", but for real case below

ckim@stph45:~] alias ddcoc "ddd caffe-fast-rcnn/python/caffe/_caffe.so `ps aux | grep python | grep tools | awk '{print $2}'`"
ckim@stph45:~] ddcoc
ddd: No match.
ckim@stph45:~] alias ddcoc
ddd caffe-fast-rcnn/python/caffe/_caffe.so ckim     29216  0.0  0.0  52596  8968 pts/8    Ss+  11:36   0:00 /home/ckim/anaconda2/bin/python -t /usr/local/bin/pydb tools/train_net_e2e.py --gpu 0 --solver models/coco/ZF/faster_rcnn_end2end/solver.prototxt --weights data/imagenet_models/ZF.v2.caffemodel --imdb coco_2014_train --iters 490000 --cfg experiments/cfgs/faster_rcnn_end2end.yml --set RNG_SEED 42 TRAIN.SCALES [400,500,600,700]

The problem is ps ... is substituted at the time alias is being defined. What I want is evaluate ps ... at the time I execute the alias. ddd is an application I can run on csh but in this alias doesn't work. How can I solve it?

Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • Try doing `"echo ... "` with double-quotes. – l'L'l Aug 25 '16 at 03:13
  • Check [\[ this \]](http://stackoverflow.com/a/24247870/1620779) helpful answer. – sjsam Aug 25 '16 at 03:24
  • @l'L'l, Ah, that works :) . (I tried that option for the original more complex case to no avail, but I might have other problem then). – Chan Kim Aug 25 '16 at 04:01
  • @l'L'l I added to the question, can you find what's wrong with the alias? – Chan Kim Aug 25 '16 at 04:08
  • What is the output of the command when not used in the alias? creating a function in your shell .profile might work better perhaps... – l'L'l Aug 25 '16 at 04:17
  • When not used in alias, the whole comand works. The `ps aux ...awk..` extracts the pid normally and the pid is used as an argument. I'll try the function method later. – Chan Kim Aug 25 '16 at 05:13

1 Answers1

0

Do you have to use an alias? I would simply transform the alias to a script or a shell function.

This would then look like (at least for bash/zsh)

function ddcoc()
{
    ddd <some absolute path>/caffe-fast-rcnn/python/caffe/_caffe.so $(ps aux | grep python | grep tools | awk '{print $2}')
}
Uroc327
  • 1,379
  • 2
  • 10
  • 28
  • ok, but I'm using csh and read csh doesn't support function. http://www.grymoire.com/Unix/CshTop10.txt . I'll try using `eval` command later. Thanks! – Chan Kim Aug 25 '16 at 11:39
  • 1
    You could also put the command into a script and execute it. – Uroc327 Aug 25 '16 at 11:40
  • you are right. In this case using a simple script seems to be the right solution. I put a script in a directory listed in PATH and can run ddd as I want. – Chan Kim Aug 25 '16 at 12:37