LoginSignup
2
2

More than 1 year has passed since last update.

MacのターミナルでBase64をデコードすると出力の末尾に"%"が挿入される

Posted at

事象

% echo $SHELL
/bin/zsh
% echo -n M | base64
TQ==
% echo TQ== | base64 -d
M%

対応策①

ZshではなくBashで実行すると%が表示されなくなる。
(出力に改行が挿入されないので,見やすさのためデコードした後echoを入れています)

% bash

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$ echo TQ== | base64 -d && echo
M
bash-3.2$

対応策②

シェルを変えたくない場合は,コマンド置換を使ってもできる。
この場合は自動改行もされる。

% echo $SHELL
/bin/zsh
% echo $(echo TQ== | base64 -d)
M

# あるいは
% echo $(base64 -d <<< TQ==)
M

参考:linux - Base64 decoding has "%" at the end of the result sometimes. Is it the result supposed to be? Any solution to that? - Stack Overflow

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2