繁体   English   中英

Shell脚本(分配给变量)不起作用

[英]Shell script (assign to variable) not working

#!/bin/bash
if [ -f "$1" ] #parameter is file name, if i exists...
then
    VARIABLE=`cat "$1"` #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"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM