Shell 脚本(分配给变量)不工作
Shell script (assign to variable) not working
#!/bin/bash
if [ -f "" ] #parameter is file name, if i exists...
then
VARIABLE=`cat ""` #assign what's inside into VARIABLE
fi
我试过 bash -x script_01.sh "file"
并且跟踪有效:
+ '[' -f file ']'
++ cat file
+ VARIABLE='Wednesday, November 4, 2015 04:45:47 PM CET'
但问题是当我回显 $VARIABLE 时,它是空的。你们对如何让它发挥作用有什么建议吗?谢谢。
VARIABLE
在运行脚本的进程中设置,而不是在 调用 脚本的进程中设置。如果你想在你当前的环境中设置它,你需要改为源文件。
. script_01.sh "file"
#!/bin/bash
if [ -f "" ] #parameter is file name, if i exists...
then
VARIABLE=`cat ""` #assign what's inside into VARIABLE
fi
我试过 bash -x script_01.sh "file"
并且跟踪有效:
+ '[' -f file ']'
++ cat file
+ VARIABLE='Wednesday, November 4, 2015 04:45:47 PM CET'
但问题是当我回显 $VARIABLE 时,它是空的。你们对如何让它发挥作用有什么建议吗?谢谢。
VARIABLE
在运行脚本的进程中设置,而不是在 调用 脚本的进程中设置。如果你想在你当前的环境中设置它,你需要改为源文件。
. script_01.sh "file"