Solved

sed - command garbled

Posted on 2008-10-09
5
1,038 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 40

Expert Comment

by:omarfarid
ID: 22676365
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
ID: 22676418
Hi omarfarid,

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

Accepted Solution

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

Expert Comment

by:omarfarid
ID: 22676453
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
ID: 22676455
Hi ozo,

It works :P "Perfect"

Thank you

Damn! just one forward slash
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

623 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