LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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 !

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

Rep: Reputation: 490Reputation: 490Reputation: 490Reputation: 490Reputation: 490
Use single quotes for the input. '!hooray!'
 
Old 01-24-2015, 12:37 AM   #3
veerain
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.

Code:
var1=value
echo "abc $var1 def"
 
  


Reply


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 03:17 AM
copy last characters of strings? Shahid nx Linux - Newbie 4 09-27-2012 08:35 PM
[SOLVED] Problem whit special characters in shell script px87 Linux - General 2 04-15-2012 04:04 PM
Ada: How do I read large blocks of characters and get strings ? muggabug Programming 0 02-10-2012 12:46 PM
shell scripting (special characters) synapse Mandriva 4 02-18-2004 07:05 AM


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

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration