Ubuntu – How to run commands from a bash file the way they run from terminal

bashcommand linescripts

Sorry for my probably very naive question.

What I mean is: how to create an executable script/bash file that would run more complex commands, commands which must normally be put in a terminal?

Specifically, I am referring to the following commands:

  • Learned about it from here:
DRI_PRIME=1 glxgears -info

That would start glxgears and put to work the ATI discrete card. Then I can monitor its temperature etc. But when I run it from terminal, I get this:

enter image description here

While when I run it with the script

#!/bin/bash

DRI_PRIME=1 glxgears -info

only the gears window is visible, not the other one with text.

I would like to be able to use a bash file and have the first result, and then run the file from a launcher.


Considering this page on aria2 and webgui-aria2, aria2 is started in that context by running in terminal a long command:

touch /path/to/download/folder/session.txt && aria2c --enable-rpc --rpc-listen-all --save-session=/path/to/download/folder/session.txt --input-file=/path/to/download/folder/session.txt -x16 -s16 -k1M --dir=/path/to/download/folder

How to run that with a script (that I would then execute from a launcher) and have the same result, the same info?

A script like so (adapted to my download folder)

#!/bin/bash

touch /home/cip/Downloads/aria2/session.txt && aria2c --enable-rpc --rpc-listen-all --save-session=/home/cip/Downloads/aria2/session.txt --input-file=/home/cip/Downloads/aria2/session.txt -x16 -s16 -k1M --dir=/home/cip/Downloads/aria2

gives nothing, while thhe programs starts.

(I'm in Xubuntu 14.04).

Best Answer

Consider this script (saved as /home/muru/test.sh):

#! /bin/bash
DRI_PRIME=1 glxgears -info

A basic launcher for this would look like (say, save it as /home/muru/test.desktop):

[Desktop Entry]
Type=Application
Terminal=true
Name=glx-gears-info
Exec=/home/muru/test.sh

Make them both executable:

chmod +x test.sh test.desktop

Now you should have these two entries in your home folder: enter image description here

Notice how the name is glx-gears-info even though the launcher's filename is test.desktop. You can double click on it to start the script: enter image description here


For a script like (say, located at /home/muru/start-aria.sh):

#!/bin/bash
touch /home/cip/Downloads/aria2/session.txt && \
    aria2c --enable-rpc --rpc-listen-all \
       --save-session=/home/cip/Downloads/aria2/session.txt \
       --input-file=/home/cip/Downloads/aria2/session.txt -x16 -s16 -k1M \
       --dir=/home/cip/Downloads/aria2

(I split the command into multiple lines for readability) the launcher file would look like (say /home/muru/start-aria.desktop):

[Desktop Entry]
Type=Application
Terminal=false
Name=Start Aria2
Exec=/home/muru/start-aria.sh

You can set Terminal=false here as this command probably doesn't need a terminal.


To get the terminal window when using Xfce launchers, tick 'Run in Terminal'.

enter image description here

A second command, that would close aria2, can be added in the same Xfce launcher: pkill aria2c

Also:

  • by adding them into a single launcher,

  • setting advanced properties like in the image below

enter image description here

(namely 'show last used item' and 'inside button'),

  • and adding two specific icons,

the launcher will always display the current status of aria2: running or closed.

enter image description here

Related Question