0

How to convert the following go code to bash

    data, _ := base64.StdEncoding.DecodeString("nJpGBA==")
    fmt.Println(data)

    //Output
    [156 154 70 4]

I got up to here

    echo nJpGBA== |base64 -d 

https://play.golang.org/p/OfyztKQINg9

1
  • What output do you expect? The same as in Go? Commented Jan 14, 2019 at 16:49

1 Answer 1

3

Not a exact match, but:

echo nJpGBA== |base64 -d  | od -A n -t u1

Output: 156 154 70 4

Note leading space and multiple spaces between.

Other solution. Assign it to an array:

val_array=( $(echo nJpGBA== |base64 -d  | od -A n -t u1) )
echo "${val_array[@]}"

Output: 156 154 70 4

The command od dumps any binary files, by default in octal values. Here it reads from stdin, as no file is given.

  • -A n suppresses the output of byte addresses
  • -t u1 prints one byte unsigned decimals
Sign up to request clarification or add additional context in comments.

1 Comment

Very nice. Could you explain the od flags ? Will it work whatever the input is or will you need to adjust the flags ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.