How to export special characters into environment variables?
I need to export special characters into an environment variable.
As most of us know usually
can be used to store the string "ABCD" in foo.
Now I need to export everything in hexadecimal form. So my "ABCD" would become "\x41\x42\x43\x44".
Naturally I tried to simply
However export did not register the backslash and thus export every character as a single standard-char.
So I ended up with
"'\' 'x' '4' '1' '\' 'x' '4' '2' '\' 'x' '4' '3' '\' 'x' '4' '4'"
stored in my variable.
Is there any way to actually export hexadecimal characters into environmental variables?
Thanks a lot in advance!
Of course "ABCD" was only an example for the purpose of clarification.
Which shell/environment are you using? I ask because in a bash environment I get the same result:
$ export xxx="\x41\x42\x43"
$ echo $xxx
In general, if you use single quotes, the contents is not treated special. Using double quotes will treat the content special.
Try using: export yyy='\x41\x42\x43'
You can also 'escape' the special chars by adding a backslash in front of (any) special char:
$ export xxx="\\x41\\x42\\x43"
$ echo xxx
Hope this helps.
In Bash, the following will work:
Thanks for the help!
The code issued by spirit receiver worked for me.
I also found an alternative way. Im going to post it in case anyone ever needs it:
You can let perl convert the hexadecimal characters into normal chars and then store these in the variable.
export foo=`perl -e 'print "\x50\x9a\x05\x40"'`
A plain echo won't convert your hex. echo -e does.
Well, on my system, Perl weighs about 1.2M. That's slightly too much for this task, I think. Bash's built-in "echo -e" should do just the same.
[Sorry, too late.]
I forgot about that bit of shell magic since I never have a need for it.
|All times are GMT -5. The time now is 05:53 AM.|