以下是一个Bash脚本的示例,用于将编码的字符串解码为字节数组:
#!/bin/bash
# 输入编码的字符串
encoded_string="SGVsbG8gd29ybGQh"
# 解码字符串为字节数组
decoded_string=$(echo "$encoded_string" | base64 --decode | xxd -p)
# 输出解码后的字节数组
echo "Decoded string: $decoded_string"
在上面的示例中,我们使用了base64
和xxd
命令来完成解码过程。首先,我们使用base64 --decode
命令将编码的字符串解码为二进制数据。然后,我们使用xxd -p
命令将二进制数据转换为十六进制字符串表示。
最后,我们通过echo
命令将解码后的字节数组输出到控制台。您可以根据需要修改encoded_string
变量的值来解码不同的字符串。