[英]when exporting environment variables with spaces in value using lastpass bash script, receiving `not a valid identifier`
I'm using lpass-env which uses the lpass cli to pull down a note from my vault and set them as environment variables.我正在使用 lpass-env,它使用 lpass cli 从我的保管库中拉下一个便笺并将它们设置为环境变量。
The note looks similar to this:该注释类似于以下内容:
VARIABLE_WITH_SPACES="abcd 1234"
VARIABLE_WITHOUT_SPACES=abcd1234
When the script runs the following command:当脚本运行以下命令时:
$(lpass show --notes mynote | awk '{ print "export", $0 }')
I get the following output:我得到以下 output:
-bash: export: `1234"': not a valid identifier
So it doesn't like the spaces in the value.所以它不喜欢值中的空格。 How can I fix this?
我怎样才能解决这个问题?
The same thing happens if you cat a file that has spaces in some of the values:如果你 cat 一个在某些值中有空格的文件,也会发生同样的事情:
$(cat file | awk '{ print "export", $0 }')
-bash: export: `1234"': not a valid identifier
Word splitting shell expansion just scans the result of command substitutions - the quotes that come after expansion of a command substitution are not special and become part of the parameters.字拆分 shell 扩展仅扫描命令替换的结果 - 命令替换扩展后出现的引号并不特殊,并且成为参数的一部分。
You could (ab-)use the source
command and pass a process substitution:您可以(ab-)使用
source
命令并传递进程替换:
. <(lpass show --notes mynote | sed 's/^/export /')
or be evil:或作恶:
eval "$(lpass show --notes mynote | sed 's/^/export /')"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.