Don T Spamme
Don T Spamme

Reputation: 209

Shell script to read line from TXT and assign to env variable?

I have a text file called VERSION.txt with only one line of content:

2.0.5

I'd like to use a shell script to read that version number and assign it to a env variable like so:

export APP_VERSION='2.0.5'

This is about as close as I could come.

input="VERSION.txt"
while IFS= read -r line
do
    export APP_VERSION=$line

echo 'App version is' ${APP_VERSION}
done < "$input"

Which seems to work, but when I echo $APP_VERSION I get a blank result.

Any tips?

Upvotes: 1

Views: 1336

Answers (2)

Nomad_Adv
Nomad_Adv

Reputation: 1

You can do something like this:

#!/bin/bash
while read -r arg_1; do 
    <your command with each arg in your text file using ${arg_1}>
done < ./<your inputs separated line by line text file>

Upvotes: 0

Cyrus
Cyrus

Reputation: 88553

input="VERSION.txt"
export APP_VERSION=$(cat "$input")
echo "App version is ${APP_VERSION}"

Upvotes: 4

Related Questions