Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a text file into an environment variable?

I have a one line text file (it will always be just one line). For example:

helloworld.txt contains "hello world"

I want to read this into an environment variable via the command prompt.

so Set MyVar=somehow reads helloworld.txt

Does anyone know how to do this?

like image 361
Shai UI Avatar asked Jun 09 '11 18:06

Shai UI


People also ask

How do you enter an environment variable?

Windows Environment Variables Do so by pressing the Windows and R key on your keyboard at the same time. Type sysdm. cpl into the input field and hit Enter or press Ok. In the new window that opens, click on the Advanced tab and afterwards on the Environment Variables button in the bottom right of the window.

Is a .env file a text file?

A . env file is a text file containing key value pairs of all the environment variables required by your application. This file is included with your project locally but not saved to source control so that you aren't putting potentially sensitive information at risk.

How do I view an environment file in Linux?

The most used command to displays the environment variables is printenv . If the name of the variable is passed as an argument to the command, only the value of that variable is displayed. If no argument is specified, printenv prints a list of all environment variables, one variable per line.

What is a .env file?

The . env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can customize your environment variables as desired by modifying your . env file.


1 Answers

set /P VARNAME=<FILENAME.TXT

This will only work with first line and will handle everything up to the end of the line.

Found at http://ss64.com/nt/set.html

like image 116
Jason Swager Avatar answered Oct 20 '22 10:10

Jason Swager