Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sed - command garbled

Posted on 2008-10-09
5
Medium Priority
?
1,050 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
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 85

Accepted Solution

by:
ozo earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Loops Section Overview

963 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