Reputation: 51
Trying to decode "ZW5jb2RlIG1lCg=="
using this script like ./decodetest.sh '"ZW5jb2RlIG1lCg=="'
doesn't return anything. I'm passing base64 string with single quotes to keep the double quotes for the command. Any help is appreciated or any alternatives.
#!/bin/ksh
OBJECT=$1
perl -MMIME::Base64 -e 'print decode_base64(${OBJECT})'
#echo ${OBJECT}
Running below on the command line correctly outputs "encode me".
perl -MMIME::Base64 -e 'print decode_base64("ZW5jb2RlIG1lCg==")'
Upvotes: 0
Views: 1031
Reputation: 118635
Shell environment variables are accessible in Perl through the %ENV
hash
perl -MMIME::Base64 -e 'print decode_base64($ENV{OBJECT})'
You may need to call export
on the variable in ksh for it to be visible to subshells.
OBJECT=$1
export OBJECT
perl -MMIME::Base64 -e 'print decode_base64($ENV{OBJECT})'
or
export OBJECT=$1
perl -MMIME::Base64 -e 'print decode_base64($ENV{OBJECT})'
Upvotes: 2
Reputation:
Rather than try to make nested quotes work, it would be cleaner to pass the argument through as an argument:
#!/bin/ksh
OBJECT=$1
perl -MMIME::Base64 -e 'print decode_base64($ARGV[0])' "$OBJECT"
Upvotes: 3