bash: set array env variable and de-referencing it from any shell script fails

前端 未结 5 1997
余生分开走
余生分开走 2020-12-04 01:49

I set the a array as an environment variable in this manner eg. script test.sh

in test.sh

#!/bin/bash
export STRING=( \"str1\" \"str2\"         


        
5条回答
  •  心在旅途
    2020-12-04 02:21

    The environment variables passed from processes to their children are unstructured strings; arrays cannot be supported. You can demonstrate this in Bash:

    export x=foo
    printenv x
    

    That outputs foo. If I now cause x to become an array

    x=(foo bar)
    printenv x
    

    We see no output (x is not exported).

提交回复
热议问题