LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [Shell] Read a File from script (https://www.linuxquestions.org/questions/programming-9/%5Bshell%5D-read-a-file-from-script-347311/)

yussef 07-27-2005 10:57 AM

[Shell] Read a File from script
 
I know it is possible to read from a file using the awk command,
but can I read a config file and put each result in a different variable of
my script.

Code:

email=user@domain
subject=subject-here

Meaning that the email and subject will be in 2 different variables.
If someone could show me...

Thank you

Matir 07-27-2005 11:14 AM

Code:

. FILE_ABOVE
echo $email
echo $subject


yussef 07-27-2005 11:18 AM

thanks Matir but could you be a bit more explicit?

Thanks for your answer though :)

Matir 07-27-2005 11:32 AM

If the file is composed of name=value pairs, you can just source it and access the name as a variable of type $name.

lostjohnny 08-19-2008 04:26 AM

Quote:

Originally Posted by Matir (Post 1768459)
If the file is composed of name=value pairs, you can just source it and access the name as a variable of type $name.

This is brilliant. I was trying for hours yesterday to find a solution to the same problem (reading a config file) and all I have to do is source the config file!

If there was a "slapping one's own forehead" smilie, I'd use it just here.

Graham


All times are GMT -5. The time now is 05:34 PM.