LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cat file with $variable (https://www.linuxquestions.org/questions/linux-newbie-8/cat-file-with-%24variable-750290/)

linuxbin 08-26-2009 01:08 AM

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

konsolebox 08-26-2009 01:54 AM

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


colucix 08-26-2009 02:03 AM

You sure the variable HostName contains a non-null string?

Tinkster 08-26-2009 02:03 AM

Quote:

Originally Posted by linuxbin (Post 3657751)
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

Disillusionist 08-26-2009 02:34 AM

Try $HOSTNAME (note uppercase)

linuxbin 08-26-2009 11:09 PM

solved
 
'EOF' did the tricks thanks konsolebox

konsolebox 08-27-2009 03:27 AM

Quote:

Originally Posted by linuxbin (Post 3659043)
'EOF' did the tricks thanks konsolebox

just tried. np.


All times are GMT -5. The time now is 08:24 PM.