i'm new to shell script. i wrote a test script that encode/decode plain text to base64 string. but it does not work what i thought. i want to decode base64 encoded string to plain text if ENCODING var is false.
my script:
#!/bin/bash
ENCODING=false
INPUT_STRING=dGVzdF9zdHJpbmcK
if [ $ENCODING ]; then
echo "$INPUT_STRING" | base64
else
echo "$INPUT_STRING" | base64 --decode
fi
output of script:
[ec2-user@ip-10-252-34-162 ~]$ ./test.sh
ZEdWemRGOXpkSEpwYm1jSwo=
the 'else' statement not working. but follow command works fine
echo "$INPUT_STRING" | base64 --decode
答案 0 :(得分:0)
Comparing your variable as strings works. I.e:
if [ "$ENCODING" == "false" ];