linuxenvironment-variables

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?


Solution

  • If your 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)