David Vypr
David Vypr

Reputation: 31

Decode from base64 and execute command

I want to execute command on Linux box, but I should send commands on base64 format.

How can I decode base64 string on Linux command and then execute the decoded string?

Upvotes: 2

Views: 8041

Answers (1)

codeforester
codeforester

Reputation: 43039

Use base64 -d:

# 'string' variable contains a base64 encoded command
command=$(base64 -d <<< "$string"); decode_status=$?
# run the command only if decode was successful
# we shouldn't enclose $command in double quotes in this case
[[ $decode_status == 0 ]] && $command

Upvotes: 5

Related Questions