Home > Back-end >  Shell script to read line from TXT and assign to env variable?
Shell script to read line from TXT and assign to env variable?

Time:10-04

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?

CodePudding user response:

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