简体   繁体   中英

call a shell script(command line tool) inside another shell script

I am using a tool called Droidbox for experiment. The tool has a shell script droidbox.sh which I can invoke through terminal.

droidbox.sh takes one argument ie path of the apk

Usage: ./droidbox.sh APK

I want to call the droidbox.sh through a shell script.

I wrote a shell script like

#!/bin/bash
ARG1="/home/xxx/a.apk"
/home/xxx/DroidBox_4.1.1/droidbox.sh "$ARG1"

I am getting error which says

python: can't open file 'scripts/droidbox.py': [Errno 2] No such file or directory

Can anybody point out what am I doing wrong?

Your error message does not come from your script, but from the called one.

It sounds like the droidbox.sh script is not very smart and requires you to set the current working directory before you can call it.

I would typically use also some more variables, so you better see what belongs together:

#!/bin/sh
set -e
BASEDIR="/home/xxx" 
DROIDDIR="$BASEDIR/DrroidBox_4.1.1"
APKFILE="$BASEDIR/a.apk"
cd "$DROIDDIR"
"$DROIDDIR/droidbox.sh" "$APKFILE"

If you dont use set -e you better combine commands which need to succeed together:

cd "$DROIDDIR" && "$DROIDDIR/droidbox.sh" "$APKFILE"

Otherwise the cd might fail when the directory is missing and all following commands execute in the wrong directory.

This error is because you're running the script in a different folder than the folder that houses your "scripts/droidbox.py" file. You can fix this in the following way(s):

  1. Move the "scripts/" folder to the directory that you're running this script out of using "mv /path/to/scripts/ ."
  2. Move your customer script to the folder that contains scripts/droidbox.py and run the script from there

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM