Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-23-2015, 06:11 PM   #1
Senior Member
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,382

Rep: Reputation: 55
How can I get shell to read special characters as strings? Such as $ or !

How can I get shell to read special characters as strings? Such as $ or !

$ ./ "!hooray!"
bash: !hooray!: event not found
$ ./ !hooray!
bash: !hooray!: event not found
If I escape it, the \ prints in the output:
$ ./ "\!hooray\!"
The code of is as follows:
$ cat 
echo "$str"
Old 01-23-2015, 07:07 PM   #2
Senior Member
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
Use single quotes for the input. '!hooray!'
Old 01-23-2015, 11:37 PM   #3
Senior Member
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
You can use double quotes if you want a variable replaced (expanded) by its value.

echo "abc $var1 def"


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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read .log format file and get special character from some lines by shell scripting samasara Linux - Newbie 32 12-21-2013 02:17 AM
copy last characters of strings? Shahid nx Linux - Newbie 4 09-27-2012 07:35 PM
[SOLVED] Problem whit special characters in shell script px87 Linux - General 2 04-15-2012 03:04 PM
Ada: How do I read large blocks of characters and get strings ? muggabug Programming 0 02-10-2012 11:46 AM
shell scripting (special characters) synapse Mandriva 4 02-18-2004 06:05 AM

All times are GMT -5. The time now is 11:32 AM.

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