Sponsored Content
Top Forums Shell Programming and Scripting Fetch the value from Here Document Post 302717839 by Don Cragun on Thursday 18th of October 2012 04:04:47 PM
Old 10-18-2012
Quote:
Originally Posted by adisky123
I have code like
Code:
var="1"
echo << EOF
export `var="2"`
EOF
echo $var

The value of var is printed here is 1 but it should be 2
Any error there?

---------- Post updated at 11:44 AM ---------- Previous update was at 10:33 AM ----------

Also tried
Code:
var="1"
echo var << EOF
echo "2"
EOF
echo $var

That isn't the way echo works and that isn't the way here-documents work.
The echo utility doesn't read standard input, so nothing being done in the here document will be echo'ed by echo.

A here-document operates in the shell execution environment of the command that will be run; not in the current shell execution environment. So, anything you execute in the here-document may affect echo's environment, but it won't be visible in the environment of the shell that ran echo.

The purpose of a here-document is to create text that will be able to be read from the file descriptor specified (fd 0 by default) by the command line that contains the here-document.

If you put the text var=valuein a here-document, the shell doesn't assign value to var; it just makes the stirng "var=value" available to be read from standard input of the command. You can see this if you use cat instead of echo:
Code:
cat <<EOF
var=value
variables are expanded (\$HOME is $HOME)
command substitutions are performed 2+2 is $(echo 2 + 2|bc)
but variables that affect the environment of the shell calling cat cannot be set
EOF

which produces
Code:
var=value
variables are expanded ($HOME is /Users/dwc)
command substitutions are performed 2+2 is 4
but variables that affect the environment of the shell calling cat cannot be set

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

echo with a here-document

I do not know how valid this post is, but here it is. I was writing a script for testing some development code that I had written. It involved many echo statements to redirect the output into a log file. Given the large number of echo statements, I took to this solution cat <<EOF >>... (2 Replies)
Discussion started by: vino
2 Replies

2. UNIX for Dummies Questions & Answers

Teaching myself Here Document

I understand that a Here Document will redirect all of the lines between the beginning marker for the here document and the ending marker into the command specified just as if the text were coming from standard input. I am trying to understand the Here Document with this example: # Menu file... (3 Replies)
Discussion started by: ericelysia
3 Replies

3. Shell Programming and Scripting

The here document <<

Hello, I want to know the use of the here document with the << operator. Tried to go through some books but the concept was not clear. Please can any1 expalin me this with a simple example. Thanks, Rahul. (6 Replies)
Discussion started by: rahulrathod
6 Replies

4. Shell Programming and Scripting

here document not working

I tried doing ftp myhost <<HERE username password quit HERE but it doesnt work. Why? When I do ftp host, I always get prompted for username, and once I type that in I get prompted for password. But when I try doing it from here document it freezes. (2 Replies)
Discussion started by: JamesByars
2 Replies

5. UNIX for Dummies Questions & Answers

fetch Variable value

Hi Guys, I have written a script that declares all the variables and its values in a conf file. Now i use a variable whose value i need to change it in one of the sub-file that is used in the script. In the startup file i want to print or check its value. The value get changed and printed... (5 Replies)
Discussion started by: Swapna173
5 Replies

6. Shell Programming and Scripting

Document

Plz can somebody give me the shell and perl scripting documents,i need to start the scrpts learning.now i know about the linux commands,but need help in putting the same in the scripting with do,if,while and also using diffrent commands in the scrpipts,pls help.. (3 Replies)
Discussion started by: satish.res
3 Replies

7. Shell Programming and Scripting

Variables in HERE DOCUMENT

Here is my problem: can we set the variables in the HERE DOCUMENT? I have tried but failed. Any one has good comments please let me know. #!/bin/csh -f pbrun -u xmgbrk runshell <<! @ $num1 = `wc -l /home/tpltp/csh/scripts/who.csh` echo "$num1" if ( $num1 > 0 ) then echo $num1 | tee -a... (1 Reply)
Discussion started by: tpltp
1 Replies

8. Shell Programming and Scripting

Here document inside a here document?

Can we use a here document inside a here document? Something like this ssh user@remotehost << REMOTE sudo vserver vsernamename enter << VSERVER perform actions on vserver. VSERVER REMOTE (6 Replies)
Discussion started by: mnanavati
6 Replies

9. Homework & Coursework Questions

HTML document

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: <HTML><HEAD><TITLE>Personal Web Page</TITLE></HEAD> <BODY BGCOLOR="WHITE"><H3> <CENTER>My Personal Page<HR>... (0 Replies)
Discussion started by: Larry_1
0 Replies

10. Shell Programming and Scripting

Fetch PID

Hi All, i get this output when i do PS UX tdntp 9263 0.0 0.0 98464 3200 pts/1 S+ 14:16 0:00 vim FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_ I want to get the PID of certain specefic filename. so i tried ps ux | pgrep... (13 Replies)
Discussion started by: asheshrocky
13 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 09:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy