sed - command garbled

Hi all,

i have this sed line below whcih is working fine.

echo "enter name"
read name
echo "enter shell"
read shell

sed -n "/$name/s/^\(.*:\).*$/\1$shell/p" /etc/passwd

The problem is:

when i enter shell as /bin/bash , the sed command gives me "command garbled" error
but when i enter shell as bash, the sed command works fine..

anyone know why?

thank you



Teh problem is:

c00kie88Asked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
sed -n "/$name/s#^\(.*:\).*\$#\1$shell#p"
0
 
omarfaridCommented:
since the first has / in it (/bin/bash) this causes sed to confuse it with its own separator /

so change to

sed -n "/$name/s#^\(.*:\).*$#\1$shell#p" /etc/passwd
0
 
c00kie88Author Commented:
Hi omarfarid,

It's no different. It still comes up command garbled
0
 
omarfaridCommented:
I think the slashes are causing the problem

start simple, then add up

echo /usr/omar | sed 's#omar#farid#'

then add other stuff
0
 
c00kie88Author Commented:
Hi ozo,

It works :P "Perfect"

Thank you

Damn! just one forward slash
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.