So I tried to fix this problem by myself for a couple of hours but I couldn't here's the code block that has a problem I changed it, rewritten, I even tried to "do" only echo after each line but it doesn't seem to work. It is a code to decrypt CSV files of a game for some event thing. In case u want, here's full code https://pastebin.com/Gv3Fvyxy

for path in $(find assets -name "*.csv")
    f=$(echo "$path" | rev | cut -d"/" -f1 | rev)
        dd if=$path bs=1 count=9 status=none
        dd if=/dev/zero bs=1 count=4 status=none
        dd if=$path bs=1 skip=9 status=none
    ) | lzma -dc -f > "decrypted/"$f

  • 2
    Possibly your file has MS-DOS CRLF line delimiters? – Stéphane Chazelas Jun 6 '20 at 6:15
  • 1
    It would be easier to computef as f=$( basename "$path" ) and safer to to call the loop with -exec from find than to rely on filenames being nice. – Kusalananda Jun 6 '20 at 6:34
  • Can't reproduce the problem. In the full code, the -n option is never checked: if appears in a block that is executed only if -h has been given but there is an exit before it. That full code also has an extra space after "extracted/". – xenoid Jun 6 '20 at 8:19
  • 1
    Install and use shellcheck. And quote every variable expansion. Especially, why quote the constant string decrypted/ but not the expansion $f after it? – Paul_Pedant Jun 6 '20 at 9:46
  • 1
    What shell is this run in? Shellcheck won't do a full check unless you provide a shebang. The name path is reserved in some shells as some kind of alias for PATH -- best not use it. – Paul_Pedant Jun 6 '20 at 9:54

An enhanced version of the script:


find assets -name '*.csv' -exec bash -c '
    f="$(awk '{print $NF}' <<< "$1")"
        dd if="$1" bs=1 count=9 status=none
        dd if=/dev/zero bs=1 count=4 status=none
        dd if="$1" bs=1 skip=9 status=none
    } | lzma -dc -f > "decrypted/$f"

' -- {} \;
  • take care of files with spaces in names
  • simplify rev|cut|rev by
  • use more quotes !

Learn how to quote properly in shell, it's very important :

"Double quote" every literal that contains spaces/metacharacters and every expansion: "$var", "$(command "$var")", "${array[@]}", "a & b". Use 'single quotes' for code or literal $'s: 'Costs $5 US', ssh host 'echo "$HOSTNAME"'. See


You don't show here the same version of script that you posted to pastebin.

The pastebin code has this line (57):

    f= $(echo "$path" | rev | cut -d "/" -f1 | rev)

In which there is an space after the =, that is a syntax problem.

Probably it is there (or close to it) that your script is failing.

And, in fact, that whole line could be simplified to:


But you also have many small code errors. Most of them could be detected and resolved by following the recommendations from shellcheck.net. Paste your script there and clean it up.

A cleaned-up version may look as:


Usage(){ echo "Usage: $0 [-n filename.apk]"; exit; }

case $1 in
    -h) Usage;;
    -n) if [ -z "$2" ];then
        echo "You need to insert a filename"
    *)  echo "Give me the clash royale filename"
        read -r filename

if [ ! -f "$filename" ];then
    echo "File \"$filename\" not found!"; exit

echo "Unzipping crash royale apk"
unzip -o -q "$filename" -d "extracted"

echo "Decrypting csv files"
mkdir decrypted
find assets -name '*.csv' -exec bash -c '
        dd if="$1" bs=1 count=9 status=none
        dd if=/dev/zero bs=1 count=4 status=none
        dd if="$1" bs=1 skip=9 status=none
    } | lzma -dc -f > "decrypted/$f"

' sh {} \;

echo "All the decrypted file are stored in the decrypted folder"

#Delete partial files
rm -r extracted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.