I am trying to use variables to construct the --command arg for gnome-terminal.

My shell script look like this:


gnome-terminal -e 'sh -c "while true; do
        python acra.py $versionCode $buildId 0 $daily
        sleep 600 # 10 mins

But when I run this script, new terminal open but it cannot recognize these variables, I'm only receive sys.argv = ['acra.py', '0'] inside my python script, so I guess the cmd was executed just like:

python acra.py 0

So how can I use variable in this case?


Assuming that gnome-terminal behaves like xterm:

gnome-terminal -e sh -c 'some commands here' sh "$variable1" "$variable2" "etc."

The strings at the end of the command line will be available inside the sh -c script as $1, $2, $3, etc. The first argument to the script, the string sh, will be placed in $0 and used in error messages by the shell.

In your case:



gnome-terminal -e sh -c '
    while true; do
        python acra.py "$1" "$2" 0 "$3"
        sleep 600
    done' sh "$versionCode" "$buildId" "$daily"

This assumes that the acra.py script is available in the current working directory.

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.