variables within sed substitutions?
Hi, I have yet another sed question. The following script unsuccessfully attempts to expand tildes within pathnames:
Code:
#!/bin/sh Code:
$HOME Code:
/home/username Thank you. |
See those single quotes?---To bash, they say: "don't attempt to interpret any special characters here--just pass them on to sed."
"$" has a different meaning to sed. By using double-quotes, the "$" will be read by bash. (Then, to get back the sed meaning, you would need to use "\$") So, the corrected line is: dir=`echo $1 | sed "s/^~/$HOME/"` Bash Guide for Beginners--by Machtelt Garrels....free at tldp.org Also there: Advanced bash scripting guide by Mendel Cooper |
Why don't simply let the bash to expand by itself (without using single quotes, as pixellany pointed out)?
Code:
#!/bin/bash Code:
/home/colucix/bin |
Quote:
Thanks to both for your answers. |
All times are GMT -5. The time now is 02:12 AM. |