[英]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.