cd `dirname `which prog``
Hey guys,
I'm trying to remember how to use the output of a nested Bash builtin call. So `which prog` gives me the path to the program, i'm interested in. Then I would like to get the directory path leading to that program and plug it into 'cd', so i end up in the directory containing the program. What am I missing? thanks for any hints. |
The syntax for command substitution that uses back ticks, does not permit nesting. Use the $(command) syntax instead:
Code:
cd $(dirname $(which prog)) |
Quote:
Thanks. |
Quote:
|
Quote:
Code:
word_count=` wc -w \`echo * | awk '{print $8}'\` ` |
The Why is $(...) preferred over `...` (backticks)? FAQ page details the differences between the two forms, including complications with nesting, escaping, and quoting.
|
All times are GMT -5. The time now is 05:54 PM. |