Skip to content
Advertisement

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?

Advertisement

Answer

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)
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement