LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 08-26-2009, 02:08 AM   #1
linuxbin
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Rep: Reputation: 0
Question cat file with $variable


How do I get my newtest.sh to have the 2 lines below?
cat >> /tmp/newtest.sh << EOF1
HostLoc="$(echo "$HostName" |awk '{print substr($0,"1",4)}')";
HostLoc='"$(echo "$HostName" |awk '{print substr($0,"1",4)}')"';
EOF1
Actual results is
HostLoc="";
HostLoc='""';
Thanks in advance
 
Old 08-26-2009, 02:54 AM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 16

Rep: Reputation: 233Reputation: 233Reputation: 233
try to add quotes to the delimeter
Code:
cat >> /tmp/newtest.sh << 'EOF1'
HostLoc="$(echo "$HostName" |awk '{print substr($0,"1",4)}')";
HostLoc='"$(echo "$HostName" |awk '{print substr($0,"1",4)}')"';
EOF1
 
Old 08-26-2009, 03:03 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
You sure the variable HostName contains a non-null string?
 
Old 08-26-2009, 03:03 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by linuxbin View Post
How do I get my newtest.sh to have the 2 lines below?
cat >> /tmp/newtest.sh << EOF1
HostLoc="$(echo "$HostName" |awk '{print substr($0,"1",4)}')";
HostLoc='"$(echo "$HostName" |awk '{print substr($0,"1",4)}')"';
EOF1
Actual results is
HostLoc="";
HostLoc='""';
Thanks in advance
What's the content of $HostName? ;}


Cheers,
Tink


P.S.: Beat by a few seconds ;D
 
Old 08-26-2009, 03:34 AM   #5
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,013

Rep: Reputation: 83
Try $HOSTNAME (note uppercase)
 
Old 08-27-2009, 12:09 AM   #6
linuxbin
LQ Newbie
 
Registered: Aug 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Thumbs up solved

'EOF' did the tricks thanks konsolebox
 
Old 08-27-2009, 04:27 AM   #7
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 16

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by linuxbin View Post
'EOF' did the tricks thanks konsolebox
just tried. np.
 
  


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
How to get variable from text file into Bash variable mcdef Linux - Software 2 06-10-2009 02:15 PM
cat file over ssh and put it into log file sinister1 Programming 2 04-24-2009 01:54 AM
How do you assign a variable to be a variable file name in a directory? David_Elliott Programming 4 04-14-2009 11:19 AM
trying to redirect text to a file to cat at later point. says file doesn't exist. dr_zayus69 Programming 1 10-02-2005 09:10 AM
how to cat a text file and save it as a variable mrobertson Programming 37 07-05-2005 09:20 AM


All times are GMT -5. The time now is 07:21 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration