LinuxQuestions.org
Review your favorite Linux distribution.
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 03-10-2009, 12:56 AM   #1
jackandking
Member
 
Registered: Dec 2004
Posts: 92

Rep: Reputation: 15
Question how to stop parsing shell variables in bash script inside cat area?


e.g.:
Code:
#!/bin/bash
cat << EOF >>/tmp/test
test `hostname` = "vm20" || return
EOF
expected content of /tmp/test:
test `hostname` = "vm20" || return

actually get:
test vm20 = "vm20" || return

further more, if there are variables like "$#,$a" inside the cat area they all will be parsed and replaced by their value in current shell.

how to stop this kind of parsing inside the cat area?
 
Old 03-10-2009, 02:34 AM   #2
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 38
You can escape the backticks using '\' to stop bash from expanding it. e.g.
Code:
 test \`hostname\` = "vm20" || return
The same holds for other things like $variable: use \$variable instead.
 
Old 03-10-2009, 06:44 AM   #3
jackandking
Member
 
Registered: Dec 2004
Posts: 92

Original Poster
Rep: Reputation: 15
got it, thanks.
 
  


Reply

Tags
cat


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
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 02:40 PM
grep and assign it's output to variables inside script itself problem xxx_anuj_xxx Programming 3 09-22-2007 11:24 PM
Parsing a File in a Bash Script TGWDNGHN Programming 4 12-02-2005 02:38 PM
(shell script) string parsing kuru Programming 4 09-12-2005 07:59 PM
File Parsing using a Shell Script yasir15 Programming 5 08-22-2003 12:17 PM


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

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