LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 06:11 PM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: lost+found
Distribution: CentOS
Posts: 1,430

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, 07:07 PM   #2
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Use single quotes for the input. '!hooray!'
 
Old 01-23-2015, 11:37 PM   #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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:17 PM.

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
Open Source Consulting | Domain Registration