Eou


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Eou
# 1  
Old 04-16-2007
Eou

I am trying to understand a shell script which has the following command:

if (...some condition); then
cat << EOU
usage: <command usage>
EOU
fi;

Can somebody please explain what cat << EOU and EOU does?

Thanks
# 2  
Old 04-16-2007
This is here document

Last edited by radoulov; 04-16-2007 at 02:33 PM..
# 3  
Old 04-16-2007
EOU is the "end input here" flag for the "here" data.

It basically works like a series of echo commands. Instead of

if [ some condition is true ]; then
echo "some stuff"
echo "some more stuff"
echo "even more..."
fi

It can be written

if [ some condition is true ]; then
cat << SOMEFLAG
some stuff
some more stuff
even more...
SOMEFLAG

The script ouputs everything via the cat command until it hits the flag.
In your case, EOU is the flag.

Sometimes this method is referred to as a "here" document.
# 4  
Old 04-16-2007
Thanks. So EOU was just a variable name. I thought it had some special meaning like EOF.
# 5  
Old 04-16-2007
Well, not exactly a "variable" name, but yeah, you can change it as long as it's the same at both ends of the command.

It's just a string of characters.
It's easy enough to call it a variable, but a variable is something verrry different, and calling it a variable would lead to confusion in discussing your scripts.

just my .025 Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question