A shell script is simply a text file containing one or more command to be executed by a shell (sh, bash, etc.). Scripts ending with .gpe will be runnable from the Games menu of your GP2X, scripts ending with .gpu from the Utility one.
If you want to do advanced scripting, a useful tutorial and guide is available here
- Important Note For Win32 Developers : the script files must be in unix format, so simply creating one in notepad and expected it to run wont work. A Win32 version of dos2unix can be downloaded from here.
Ending a bash script
To return to the menu after shell execution add this as common ending:
# return to the menu screen cd /usr/gp2x sync exec /usr/gp2x/gp2xmenu
# return to the menu screen cd /usr/gp2x sync /usr/gp2x/gp2xmenu
as the script will stay in memory as a running process
A simple directory listing script
#!/bin/sh # lets get a directory listing onto our SD card of the GP2X ls -laR / > /mnt/sd/ls_laR.txt # sync the SD card so that everything is written. sync # return to the menu screen cd /usr/gp2x exec /usr/gp2x/gp2xmenu
SD Cards and mounting
Scripts that are opened from the SD card keep the SD card open. which makes it difficult to unmount the card on the fly. If you have a retail unit, you may find the following useful.
The unmount.gpu "utility"
Save as unmount.gpu (Unix line endings!!)
#!/bin/sh umount /mnt/sd cd /usr/gp2x exec /usr/gp2x/gp2xmenu
Now if you copy this file to /mnt/nand, you will be able to access it from the Nand section in the utilities menu of the gp2xmenu.
- IMPORTANT* If you have run a program that didn't use exec, and is
still shown as a running process, this will not successfully unmount the card. Check after running the unmount script that the SD directory is empty before removing the card.
Example installer script:
install_unmount.gpu (Put in same directory as unmount.gpu and keep in mind the Unix line endings)
#!/bin/sh sync cp ./unmount.gpu /mnt/nand/unmount.gpu sync cd /usr/gp2x exec /usr/gp2x/gp2xmenu
This should help those using card readers letting you quickly put a new file or two on the card and pop it in to test, without power cycling the unit.