Solved

sed - command garbled

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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