Skip to main content
Added notes about the single quote case, and updated the awk syntax to be conformant with different versions.
Source Link

As the other posts point out, the most common shells do not allow for setting environment variables with periods in the name. However, I have found situations, particularly involving Docker and invoked programs, where the software required key values with periods.

However, in each of these situations, those key-value pairs could be passed to the program through other means than just environment variables. For example, in Ant, you can use the "-propertyfile (filename)" to pass in a property file formatted collection of key-values. Confd allows for "-backend file -file (yaml file)".

I passed the environment variables in the form "C__any_value='my.property.key=the value'". I then switched the program invocation to first generate the file:

set | awk -e- 'BEGIN { FS="'\''" } /^C__/ {print $2}' > my-key-values.txt

The set command, in Borne Shell, will output each property on a separate line in the form

C__any_value='my.property.key=the value'

The awk command will process only the environment variables starting with C__, then extract the values contained in the single quotes.

This method requires the environment variable value to be set in the precise form that the processing program requires. Additionally, if your property value or key will contain single quotes, then you will need to change the awk field separator character to something you know that won't appear, and surround the value with that character. For example, to use % as the separator:

$ C__1='%myC__1="%my.key=the"value%'key=the'value%"
$ set | awk -e- 'BEGIN { FS="%" } /^C__/ {print $2}'
my.key=the"valuekey=the'"'"'value

(the precise output will depend on your shell.) You will need to take extra steps to decode the quote escaping.

As the other posts point out, the most common shells do not allow for setting environment variables with periods in the name. However, I have found situations, particularly involving Docker and invoked programs, where the software required key values with periods.

However, in each of these situations, those key-value pairs could be passed to the program through other means than just environment variables. For example, in Ant, you can use the "-propertyfile (filename)" to pass in a property file formatted collection of key-values. Confd allows for "-backend file -file (yaml file)".

I passed the environment variables in the form "C__any_value='my.property.key=the value'". I then switched the program invocation to first generate the file:

set | awk -e 'BEGIN { FS="'\''" } /^C__/ {print $2}' > my-key-values.txt

The set command, in Borne Shell, will output each property on a separate line in the form

C__any_value='my.property.key=the value'

The awk command will process only the environment variables starting with C__, then extract the values contained in the single quotes.

This method requires the environment variable value to be set in the precise form that the processing program requires. Additionally, if your property value or key will contain single quotes, then you will need to change the awk field separator character to something you know that won't appear, and surround the value with that character. For example, to use % as the separator:

$ C__1='%my.key=the"value%'
$ set | awk -e 'BEGIN { FS="%" } /^C__/ {print $2}'
my.key=the"value

As the other posts point out, the most common shells do not allow for setting environment variables with periods in the name. However, I have found situations, particularly involving Docker and invoked programs, where the software required key values with periods.

However, in each of these situations, those key-value pairs could be passed to the program through other means than just environment variables. For example, in Ant, you can use the "-propertyfile (filename)" to pass in a property file formatted collection of key-values. Confd allows for "-backend file -file (yaml file)".

I passed the environment variables in the form "C__any_value='my.property.key=the value'". I then switched the program invocation to first generate the file:

set | awk -- 'BEGIN { FS="'\''" } /^C__/ {print $2}' > my-key-values.txt

The set command, in Borne Shell, will output each property on a separate line in the form

C__any_value='my.property.key=the value'

The awk command will process only the environment variables starting with C__, then extract the values contained in the single quotes.

This method requires the environment variable value to be set in the precise form that the processing program requires. Additionally, if your property value or key will contain single quotes, then you will need to change the awk field separator character to something you know that won't appear, and surround the value with that character. For example, to use % as the separator:

$ C__1="%my.key=the'value%"
$ set | awk -- 'BEGIN { FS="%" } /^C__/ {print $2}'
my.key=the'"'"'value

(the precise output will depend on your shell.) You will need to take extra steps to decode the quote escaping.

Added an example for using a different field separator.
Source Link

As the other posts point out, the most common shells do not allow for setting environment variables with periods in the name. However, I have found situations, particularly involving Docker and invoked programs, where the software required key values with periods.

However, in each of these situations, those key-value pairs could be passed to the program through other means than just environment variables. For example, in Ant, you can use the "-propertyfile "(filename)" to pass in a property file formatted collection of key-values. Confd allows for "-backend file -file "(yaml file)".

I passed the environment variables in the form "C__any_value='my.property.key=the value'". I then switched the program invocation to first generate the file:

set | awk -e 'BEGIN { FS="'\''" } /^C__/ {print $2}' > my-key-values.txt

The set command, in Borne Shell, will output each property on a separate line in the form

C__any_value='my.property.key=the value'

The awk command will process only the environment variables starting with C__, then extract the values contained in the single quotes.

This method requires the environment variable value to be set in the precise form that the processing program requires. Additionally, if your property value or key will contain single quotes, then you will need to change the awk field separator character to something you know that won't appear, and surround the value with that character. For example, to use % as the separator:

$ C__1='%my.key=the"value%'
$ set | awk -e 'BEGIN { FS="%" } /^C__/ {print $2}'
my.key=the"value

As the other posts point out, the most common shells do not allow for setting environment variables with periods in the name. However, I have found situations, particularly involving Docker and invoked programs, where the software required key values with periods.

However, in each of these situations, those key-value pairs could be passed to the program through other means than just environment variables. For example, in Ant, you can use the "-propertyfile " to pass in a property file formatted collection of key-values. Confd allows for "-backend file -file ".

I passed the environment variables in the form "C__any_value='my.property.key=the value'". I then switched the program invocation to first generate the file:

set | awk -e 'BEGIN { FS="'\''" } /^C__/ {print $2}' > my-key-values.txt

The set command, in Borne Shell, will output each property on a separate line in the form

C__any_value='my.property.key=the value'

The awk command will process only the environment variables starting with C__, then extract the values contained in the single quotes.

This method requires the environment variable value to be set in the precise form that the processing program requires. Additionally, if your property value or key will contain single quotes, then you will need to change the awk field separator character to something you know that won't appear.

As the other posts point out, the most common shells do not allow for setting environment variables with periods in the name. However, I have found situations, particularly involving Docker and invoked programs, where the software required key values with periods.

However, in each of these situations, those key-value pairs could be passed to the program through other means than just environment variables. For example, in Ant, you can use the "-propertyfile (filename)" to pass in a property file formatted collection of key-values. Confd allows for "-backend file -file (yaml file)".

I passed the environment variables in the form "C__any_value='my.property.key=the value'". I then switched the program invocation to first generate the file:

set | awk -e 'BEGIN { FS="'\''" } /^C__/ {print $2}' > my-key-values.txt

The set command, in Borne Shell, will output each property on a separate line in the form

C__any_value='my.property.key=the value'

The awk command will process only the environment variables starting with C__, then extract the values contained in the single quotes.

This method requires the environment variable value to be set in the precise form that the processing program requires. Additionally, if your property value or key will contain single quotes, then you will need to change the awk field separator character to something you know that won't appear, and surround the value with that character. For example, to use % as the separator:

$ C__1='%my.key=the"value%'
$ set | awk -e 'BEGIN { FS="%" } /^C__/ {print $2}'
my.key=the"value
Source Link

As the other posts point out, the most common shells do not allow for setting environment variables with periods in the name. However, I have found situations, particularly involving Docker and invoked programs, where the software required key values with periods.

However, in each of these situations, those key-value pairs could be passed to the program through other means than just environment variables. For example, in Ant, you can use the "-propertyfile " to pass in a property file formatted collection of key-values. Confd allows for "-backend file -file ".

I passed the environment variables in the form "C__any_value='my.property.key=the value'". I then switched the program invocation to first generate the file:

set | awk -e 'BEGIN { FS="'\''" } /^C__/ {print $2}' > my-key-values.txt

The set command, in Borne Shell, will output each property on a separate line in the form

C__any_value='my.property.key=the value'

The awk command will process only the environment variables starting with C__, then extract the values contained in the single quotes.

This method requires the environment variable value to be set in the precise form that the processing program requires. Additionally, if your property value or key will contain single quotes, then you will need to change the awk field separator character to something you know that won't appear.