Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make environmental variable equal the contents of a file

I am working on linux and I want to set an environmental variable to the contents of a file: vi file:

the env var should equal everything in here

Now the file has a lot of " and other special characters and it will a take a lot of time to escape them all. Is there an easier way?

like image 764
ban Avatar asked Jul 30 '13 16:07

ban


People also ask

How do I set an environment variable in a text file?

If filename is x. txt , you can use command substitution to set the content of that file as an environment variable. Please explain why this would work instead of just giving an answer. A more recent syntax is export C=$(cat x.

Can we use environment variables in properties file?

You can put environment variables in your properties file, but Java will not automatically recognise them as environment variables and therefore will not resolve them. In order to do this you will have to parse the values and resolve any environment variables you find.

Which command is used to access the contents of an environment variable?

The command env displays all environment variables and their values.


1 Answers

If filename is x.txt, you can use command substitution to set the content of that file as an environment variable.

export C=$(cat x.txt)
like image 176
kevoroid Avatar answered Oct 01 '22 07:10

kevoroid