LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash Script Variables Handling (https://www.linuxquestions.org/questions/linux-general-1/bash-script-variables-handling-896737/)

protocol 08-11-2011 07:40 AM

Bash Script Variables Handling
 
Hello all.

I have the following script:

Code:

#!/bin/bash

a='MIME-Version: 1.0\n'
b="Subject: Message Title\n"
c="From: someone@thatdomain.net\n"
d="Content-Type: text/html; charset=utf-8\n"
e="Content-Disposition: inline\n"
f="<html>Hello\n"
g="</html>\n"

all=$a$b$c$d$e$f$g

echo $all > sendmail someone@somedomain.com

I obviously wish to send (pipe?) the concatenated result of my a,b,c,d,e,f,g variables as input to sendmail command. However, it does not work.

Also, i wish to read the contents of a simple text file and assign that content to yet another variable that will also be used in this context.

Any help will be greatly appreciated.

Panos

catkin 08-11-2011 09:33 AM

The pipe symbol is |

> is a redirection operator; as used in your script it should have created a file called sendmail with what you wanted to send to the sendmail command.

$all contains linends so you need to double quote it or bash will turn the linends into single spaces.

protocol 08-11-2011 10:32 AM

Quote:

Originally Posted by catkin (Post 4439667)
The pipe symbol is |
$all contains linends so you need to double quote it or bash will turn the linends into single spaces.

Actually, i had to

echo -e $all | ...

that solved this particular problem.

Thank you for helping out.

:)


All times are GMT -5. The time now is 09:06 AM.