Shell 从 TXT 读取行并分配给环境变量的脚本?
Shell script to read line from TXT and assign to env variable?
我有一个名为 VERSION.txt 的文本文件,其中只有一行内容:
2.0.5
我想使用 shell 脚本来读取该版本号并将其分配给环境变量,如下所示:
export APP_VERSION='2.0.5'
这是我所能想到的最接近的结果。
input="VERSION.txt"
while IFS= read -r line
do
export APP_VERSION=$line
echo 'App version is' ${APP_VERSION}
done < "$input"
这似乎有效,但是当我 echo $APP_VERSION
我得到一个空白结果。
有什么建议吗?
input="VERSION.txt"
export APP_VERSION=$(cat "$input")
echo "App version is ${APP_VERSION}"
我有一个名为 VERSION.txt 的文本文件,其中只有一行内容:
2.0.5
我想使用 shell 脚本来读取该版本号并将其分配给环境变量,如下所示:
export APP_VERSION='2.0.5'
这是我所能想到的最接近的结果。
input="VERSION.txt"
while IFS= read -r line
do
export APP_VERSION=$line
echo 'App version is' ${APP_VERSION}
done < "$input"
这似乎有效,但是当我 echo $APP_VERSION
我得到一个空白结果。
有什么建议吗?
input="VERSION.txt"
export APP_VERSION=$(cat "$input")
echo "App version is ${APP_VERSION}"