How to export dot separated environment variables

前端 未结 4 2073
粉色の甜心
粉色の甜心 2021-02-14 17:56

Execution of

user@EWD-MacBook-Pro:~$ export property.name=property.value

Gives me

-bash: export: `property.name=property.value\         


        
4条回答
  •  北海茫月
    2021-02-14 18:37

    As others have said, bash doesn't allow it so you'll have to use your favourite scripting language to do it. For example, in Perl:

    perl -e '$ENV{"property.name"} = "property.value"; system "bash"'
    

    This will fire up a subshell bash with the property.name environment variable set, but you still can't access that environment variable from bash (although your program will be able to see it).

    Edit: @MarkEdgar commented that the env command will work too:

     env 'property.name=property.value' bash # start a subshell, or
     env 'property.name=property.value' command arg1 arg2 ...   # Run your command
    

    As usual, you only require quotes if you need to protect special characters from the shell or want to include spaces in the property name or value.

提交回复
热议问题