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:
f=${path##*/}
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:
#!/bin/bash
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"
Usage
fi
filename=$2
;;
*) echo "Give me the clash royale filename"
read -r filename
;;
esac
if [ ! -f "$filename" ];then
echo "File \"$filename\" not found!"; exit
fi
#Unzipping
echo "Unzipping crash royale apk"
unzip -o -q "$filename" -d "extracted"
#Decrypting
echo "Decrypting csv files"
mkdir decrypted
find assets -name '*.csv' -exec bash -c '
f="${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"
' sh {} \;
echo "All the decrypted file are stored in the decrypted folder"
#Delete partial files
rm -r extracted
f
asf=$( basename "$path" )
and safer to to call the loop with-exec
fromfind
than to rely on filenames being nice. – Kusalananda♦ Jun 6 '20 at 6:34-n
option is never checked: if appears in a block that is executed only if-h
has been given but there is anexit
before it. That full code also has an extra space after"extracted/"
. – xenoid Jun 6 '20 at 8:19shellcheck
. And quote every variable expansion. Especially, why quote the constant stringdecrypted/
but not the expansion$f
after it? – Paul_Pedant Jun 6 '20 at 9:46path
is reserved in some shells as some kind of alias forPATH
-- best not use it. – Paul_Pedant Jun 6 '20 at 9:54