Solved

sed - command garbled

Posted on 2008-10-09
5
1,033 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 101
xyBalance chalenge 58 96
Expand data scrubbing tool 13 35
Problem to App 4 99
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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

821 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