On Linux I can do:

echo ${ANDROID_KEYSTORE} | base64 -di > android/keystores/staging.keystore

But on macOS, the same commands give:

base64: option requires an argument -- i
Usage:  base64 [-hvDd] [-b num] [-i in_file] [-o out_file]
  -h, --help     display this message
  -Dd, --decode   decodes input
  -b, --break    break encoded string into num character lines
  -i, --input    input file (default: "-" for stdin)
  -o, --output   output file (default: "-" for stdout)

I have tried to replace -di with --decode --input, but it didn't help.

  1. How do I fix the macOS command?
  2. Is there a command that works both on Linux (Debian/Ubuntu) and macOS?

1 Answer 1


If you want portability, you'll have to implement the linux-flavour's -i yourself

# don't forget to quote the variable!
| sed 's/[^A-Za-z0-9+/=]//g' \
| base64 -d

The sed command drops invalid characters

  • This is great answer! Thanks Commented Oct 31, 2022 at 17:55
  • Also, MacOS base64 uses -D, not -d
    – tripleee
    Commented Oct 31, 2022 at 18:52
  • 1
    @tripleee It uses -d, -D, and --decode and they all mean the same thing.
    – Kusalananda
    Commented Nov 1, 2022 at 7:28
  • 1
    Potentially quicker alternative to the sed command: tr -d 'A-Z0-9+/='.
    – Kusalananda
    Commented Nov 1, 2022 at 7:28
  • @Kusalananda Hmmm, thanks. I had to unlearn -d when I got a Mac but I guess it has acquired this option synonym since then.
    – tripleee
    Commented Nov 1, 2022 at 8:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .