Skip to main content
2 of 4
fix code block; use syntax highlighting and code escapes

Executing a shell script in linux

I am a noob in linux hence this might come as a silly question. I have a windows system,so I downloaded cygwin to help me execute linux/unix commands.I need to execute a shell script on a bunch of apks stored inside a folder (got the script here).

This is the script:

#!/bin/bash
cd $1

for filename in *.apk
do
    unzip -d $filename.extract $filename META-INF/CERT.RSA
    if [ -f $filename.extract/META-INF/CERT.RSA ]
        then
        mkdir `keytool -printcert -v -file $filename.extract/META-INF/CERT.RSA|grep SerialNumber| cut -c 19-23`
        mv $filename `keytool -printcert -v -file $filename.extract/META-INF/CERT.RSA|grep SerialNumber| cut -c 19-23`/$filename
        mv `echo $filename | sed 's/\(.*\.\)apk/\1odex/'` `keytool -printcert -v -file $filename.extract/META-INF/CERT.RSA|grep SerialNumber| cut -c 19-23`/`echo $filename | sed 's/\(.*\.\)apk/\1odex/'`
        rm -rf $filename.extract
    else
        mkdir none
        mv $filename none
        mv `echo $filename | sed 's/\(.*\.\)apk/\1odex/'` none
        rm -rf $filename.extract
    fi
done;

mkdir other
mv * other
mv other/b399 platform
mv other/f2a7 shared
mv other/f2b9 media
mv other/936e test

In the terminal I execute the command sh cert.sh,but I get the below error:

enter image description here

Strangely,when I execute cert.sh - the script runs and separates my apks into different folders,but I am not sure if it runs correctly as the proper command to run a shell script is sh cert.sh.