If I understood you correctly, you want to have
base64 file > sample1.txt
base64 file | base64 > sample2.txt
base64 file | base64 | base64 > sample3.txt
...
Since you want to have a file for each step, you don't need variables. Just encode the last file to generate the next one:
#!/bin/bash
ln myfiletoencode sample0.txt
for i in {1..5}; do
base64 "sample$((i-1)).txt" > "sample$i.txt"
done
rm sample0.txt
Keep in mind that equivalent base64 encodings can be formatted differently. You can add linebreaks whenever you like. Example:
$ seq 23 | base64
MQoyCjMKNAo1CjYKNwo4CjkKMTAKMTEKMTIKMTMKMTQKMTUKMTYKMTcKMTgKMTkKMjAKMjEKMjIK
MjMK
$ seq 23 | base64 -w0
MQoyCjMKNAo1CjYKNwo4CjkKMTAKMTEKMTIKMTMKMTQKMTUKMTYKMTcKMTgKMTkKMjAKMjEKMjIKMjMK
When you encode this encoding again you get different encodings depending on the formatting (note the different length and suffix wpNak1LCg==
!= 01qTUs=
):
$ seq 23 | base64 | base64
TVFveUNqTUtOQW8xQ2pZS053bzRDamtLTVRBS01URUtNVElLTVRNS01UUUtNVFVLTVRZS01UY0tN
VGdLTVRrS01qQUtNakVLTWpJSwpNak1LCg==
$ seq 23 | base64 -w0 | base64
TVFveUNqTUtOQW8xQ2pZS053bzRDamtLTVRBS01URUtNVElLTVRNS01UUUtNVFVLTVRZS01UY0tN
VGdLTVRrS01qQUtNakVLTWpJS01qTUs=
Therefore I'd suggest do disable all linebreaks in the output using base64 -w0
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…