Solved

sed - command garbled

Posted on 2008-10-09
5
1,024 Views
Last Modified: 2013-12-26
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:

0
Comment
Question by:c00kie88
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
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
 

Author Comment

by:c00kie88
Comment Utility
Hi omarfarid,

It's no different. It still comes up command garbled
0
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
Comment Utility
sed -n "/$name/s#^\(.*:\).*\$#\1$shell#p"
0
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
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
 

Author Comment

by:c00kie88
Comment Utility
Hi ozo,

It works :P "Perfect"

Thank you

Damn! just one forward slash
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now