LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-25-2010, 04:56 AM   #1
Moshanator
LQ Newbie
 
Registered: Aug 2010
Distribution: Ubuntu, Arch
Posts: 3

Rep: Reputation: 0
sed exclamation


Hi,
trying to automatically disable some DAEMONS in /etc/rc.conf. This requires inserting ecxlamation signs itno the file.
The example command
Code:
echo Hi?|sed 's/?/!/'
returns "unterminated `s' command".
but
Code:
echo netfs|sed 's/netfs/!netfs/'
returns !netfs as expected.
Where does the difference come from?

Last edited by Moshanator; 08-25-2010 at 05:07 AM.
 
Old 08-25-2010, 05:18 AM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Odd. Try this one:
Code:
echo 'Hi?' | sed 's/?/\!/'
 
1 members found this post helpful.
Old 08-25-2010, 05:25 AM   #3
giammy
Member
 
Registered: Feb 2010
Posts: 36

Rep: Reputation: 20
Quote:
Originally Posted by Moshanator View Post
Hi,
trying to automatically disable some DAEMONS in /etc/rc.conf. This requires inserting ecxlamation signs itno the file.
The example command
Code:
echo Hi?|sed 's/?/!/'
returns "unterminated `s' command".
but
Code:
echo netfs|sed 's/netfs/!netfs/'
returns !netfs as expected.
Where does the difference come from?
Hi,

I suppose the difference is that the ? is probably interpreted as a specia character
by the shell.
In my system, Mac OS X 10.6, with the default shell (Terminal.app) I
correctly get:

Code:
~ $ echo Hi?|sed 's/?/!/'
Hi!
try escaping the "?"

bye
giammy
 
Old 08-25-2010, 08:20 AM   #4
Moshanator
LQ Newbie
 
Registered: Aug 2010
Distribution: Ubuntu, Arch
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by konsolebox View Post
Odd. Try this one:
Code:
echo 'Hi?' | sed 's/?/\!/'
Code:
echo 'Hi?' | sed 's/?/\!/'
Hi!
Very strange. Why would I need to escape the ! in some cases but not others?
Which is why I checked my bash history and discovered this:
Code:
echo Hi?|sed 's/?/!'
Silly me, the last / was missing all along. Should've checked that in the first place.
Let's hope you won't have to see more questions like this one. I really appreciate your help.
 
Old 08-25-2010, 09:08 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
It may not be the problem you're experiencing, but it should be pointed out that ! is generally seen as a special character in interactive shells. It has the function of starting a history expansion, and if followed by a number or string that references a previous command, it will insert it into the current command at that location. It will also likely spit out an error if followed by something unrecognized as one.

This even works inside of double quotes, but single quotes or the backslash will escape it.

Try this, for example:
Code:
echo "Hi?" | sed "s/?/!!/"
!! expands to the previous command entered, so you'll probably get something like Himplayer pr0n.avi as a result.

Note though that this isn't usually a problem in scripts, only the command line. See the HISTORY EXPANSION section in the bash man page for details.
 
1 members found this post helpful.
  


Reply

Tags
bash, sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can't Type an Exclamation Mark wingman358 Ubuntu 2 07-06-2010 03:30 PM
[SOLVED] Another thread about escaping an exclamation point in bash. pr_deltoid Programming 4 06-26-2010 03:27 PM
Server Indicate Exclamation mark (!) Prabuddha Linux - Hardware 1 06-15-2009 07:43 AM
Exclamation The smsc9115 driver can't receive normally kine920 Linux - Embedded & Single-board computer 3 07-17-2008 11:24 PM
Shell scripting: exclamation marks in strings Dark_Helmet Programming 9 06-16-2003 06:32 PM


All times are GMT -5. The time now is 04:00 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration