I would like to export a variable name with spaces. Is it possible in shell export
command?
{'Truststore Filename': '/hom/truststore.jks', 'Truststore Password': 'pass'}
$ export 'Truststore Password'=clientpass
-bash: export: `Truststore Password=clientpass': not a valid identifier
But i would like to export the variables using export
command because we have more than more than one variable to be exported which has spaces in names.
However, the following way works.
$ env 'Truststore Password'=clientpass 'Truststore Filename'=/hom/truststore.jks python3 script.py
No, this is not possible, as a variable in bash cannot have a name that includes spaces:
name
A word consisting solely of letters, numbers, and underscores, and beginning with a letter or underscore.
Name
s are used as shell variable and function names. Also referred to as anidentifier
.
env
, as you noticed, plays by different rules:
Environment variable names can be empty, and can contain any characters other than ‘=’ and ASCII NUL. However, it is wise to limit yourself to names that consist solely of underscores, digits, and ASCII letters, and that begin with a non-digit, as applications like the shell do not work well with other names.
(source: info '(coreutils) env invocation'
; emphasis mine)
Case in point, here's another post with an answer about how much of a pain it is to grab the output of an environment variable with spaces
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With