Link to home
Start Free TrialLog in
Avatar of sonriks
sonriks

asked on

using a variable in a sed statement

I can't get this sed statement to work. Trying to use a variable. Any ideas?

cp /etc/shadow /etc/shadow.bak

OPASSWD=`grep ttc_root /etc/shadow.bak | awk -F: '{print $2}'`

(OPASSWD is the encrypted password, and may contain metacharacters)

sed -e 's/$OPASSWD/spoo/' /etc/shadow.bak

thanks
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Use double quotes instead of single quotes.  :)

  sed -e "s/$OPASSWD/spoo/" /etc/shadow.bak


Kent
Avatar of sonriks
sonriks

ASKER

Thanks, Kent .. that worked like a charm for a "plain" string.

I need this to work for variables that contains metacharacters, as many entries in the shadow file do, characters like "/", "\", "$". etc.

OPASSWD=U/gx5Pid8Ykmk

Is there some way that the string with metachars being taken as a literal?

thanks
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sonriks

ASKER

Thanks. I used a ":" as the delimiter and it worked fine!