LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 01: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, 01:54 AM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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, 02:03 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

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

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 02:34 AM   #5
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,039

Rep: Reputation: 98
Try $HOSTNAME (note uppercase)
 
Old 08-26-2009, 11:09 PM   #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, 03:27 AM   #7
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
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 01:15 PM
cat file over ssh and put it into log file sinister1 Programming 2 04-24-2009 12:54 AM
How do you assign a variable to be a variable file name in a directory? David_Elliott Programming 4 04-14-2009 10: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 08:10 AM
how to cat a text file and save it as a variable mrobertson Programming 37 07-05-2005 08:20 AM

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

All times are GMT -5. The time now is 10:55 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
Open Source Consulting | Domain Registration