Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux command and eof in one line

I want to ask if is possible to combine linux command and <

sendmail -S "lalalal" -f "dailaakak" -au "kakakak" <<EOF
>lalal:lalal
>opp:ttt
>ggg:zzz
EOF

I want to have something like that sendmail -S "lalalal" -f "dailaakak" -au "kakakak" <<EOF; lalal:lalal; opp:ttt; ggg:zzz; EOF

I need to use that not in bash script

like image 353
Dainius Avatar asked Nov 06 '25 08:11

Dainius


2 Answers

If it has to be in one line without newlines use that:

echo -e "lalal:lalal\nopp:ttt\nggg:zzz" | sendmail -S "lalalal" -f "dailaakak" -au "kakakak"

echo -n interpretes escapes characters such as \n as a newline.

like image 128
chaos Avatar answered Nov 08 '25 11:11

chaos


If you are asking whether you can use the << EOF in an interactive shell then the answer is yes, you can.

Note this functionality is called here document and that there can be any word instead of EOF. For example:

$ cat - << someword
> Here you
> can
> write text with as many
> newlines as you want.
> someword
Here you
can
write text with as many
newlines as you want.

(cat - prints whatever it receives on stdin)

For more information on here documents you can read for example this: http://tldp.org/LDP/abs/html/here-docs.html

like image 32
geckon Avatar answered Nov 08 '25 12:11

geckon