[英]Bash variable substitution when using a command line argument file
FILEDIR=/home/myuserdir/audit
FILE=auditreport.csv
上面的變量在我的配置文件中。
我有一個使用配置文件運行的 bash 腳本:
for file in `ls ${FILEDIR}/${FILE}`
它確實看到了我的路徑,它將進入根目錄或/
目錄,而不是進入我的/home/myuserdir/audit
目錄。 但是如果我在腳本中而不是在配置文件中聲明變量,它就可以完美運行並且找到正確的目錄。 我究竟做錯了什么? 不幸的是,我必須使用配置文件運行腳本,以便於進行自定義。
我試圖將語句包裝在“”
,但它仍然不起作用。
預期的結果是我希望腳本轉到/home/myuserdir/audit
而不是主目錄。
您必須獲取配置文件,而不僅僅是啟動它!
我的配置文件
ConfigFileDir=/home/myuserdir/audit
ConfigFile=auditreport.csv
你的劇本
# source my.config at the top of your script
source my.config
# and use the variables
echo "$ConfigFileDir/$ConfigFile"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.