I have a username and password variables. I want to encode them to base64 with the format of username:password.
#!/bin/bash
username=username
password=password
echo Encoding username/password...
echo $username:$password | base64
That works, but I'm not sure how to put the output in a variable instead of writing it to the console.
On a side note, why is the output different than a website like https://www.base64encode.org/?
Using $( ... ), store the result in a variable.
And use -n to not include LF.
var=$(echo -n $username:$password | base64)
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