![](/img/trans.png)
[英]"export: `=': not a valid identifier" when exporting variables
[英]when exporting environment variables with spaces in value using lastpass bash script, receiving `not a valid identifier`
我正在使用 lpass-env,它使用 lpass cli 從我的保管庫中拉下一個便箋並將它們設置為環境變量。
該注釋類似於以下內容:
VARIABLE_WITH_SPACES="abcd 1234"
VARIABLE_WITHOUT_SPACES=abcd1234
當腳本運行以下命令時:
$(lpass show --notes mynote | awk '{ print "export", $0 }')
我得到以下 output:
-bash: export: `1234"': not a valid identifier
所以它不喜歡值中的空格。 我怎樣才能解決這個問題?
如果你 cat 一個在某些值中有空格的文件,也會發生同樣的事情:
$(cat file | awk '{ print "export", $0 }')
-bash: export: `1234"': not a valid identifier
字拆分 shell 擴展僅掃描命令替換的結果 - 命令替換擴展后出現的引號並不特殊,並且成為參數的一部分。
您可以(ab-)使用source
命令並傳遞進程替換:
. <(lpass show --notes mynote | sed 's/^/export /')
或作惡:
eval "$(lpass show --notes mynote | sed 's/^/export /')"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.