You know how to start programs in the console with program options and arguments from working with Linux. So the first command starts the editor program' gedit', opens the file' set_color. sh' in the home directory and places the cursor in the opened file in the 5th line at position 9:
hans@linux:~$ gedit ./set_color.sh +5:9 hans@linux:~$ gnome-terminal --geometry 80x20+100+100 -t 'ROOT-TERMINAL' -e command.sh
The function of the presented program (bash script)' set_color. sh' consists of assigning 3 (start) values to arguments $1 to $3 by means of the command' let' internally, depending on the number of arguments passed, and then assigning these values to the variables R, G and B or the variables R, G and B with the values of the 3 arguments passed. A (colour) value is then calculated and displayed with R, G and B.
#!/bin/bash if [ $# -ne 3 ] # If the number of arguments passed is not equal to 3, ... then set 220 20 180 # then set RGB default values: $1=220(R), $2=20(G) and $3=180(B) ... R=$1 G=$2 B=$3 else # otherwise set R, G and B from the three arguments R=$1 G=$2 B=$3 fi let color=$R*256*256+$G*256+$B # Calculate colour value echo colour value = $color echo Continue with ENTER... read dummy
In general:
The script' set_color. sh' is started first with exactly three arguments and then only with two arguments. The arguments are not checked for validity in the context of RGB color values[0… 255]:
hans@linux:~$ chmod +x set_color.sh # Das Skript ausführbar machen
hans@linux:~$ ./set_color.sh 10 20 128 # 3 Argumente Farbwert = 660608 Weiter mit ENTER...
hans@linux:~$ $HOME/set_color.sh 0 128 # 2 Argumente Farbwert = 14423220 (Kommentar: $1=220 , $2=20 , $3=180) Weiter mit ENTER...
Of course, you can also pass arguments to a Gambas program - which should be executed by the Gambas interpreter:
hans@linux:~$ gbx3 $HOME/ColorSelectBP -- 225 110 60 Anzahl der übergebenen Argumente = 3 0. Agument = ColorSelectBP 1. Agument = 225 2. Agument = 110 3. Agument = 60
As a separator symbol between the Gambas project directory and the arguments,“–” is used, as indicated in the help for the interpreter gbx3, if you interpret <arguments> as a placeholder for a list of arguments separated by spaces:
hans@linux:~$ gbx3 -h ... Usage: gbx3 [options] [<project file>] [-- <arguments>]
In the following two examples exactly one option k is passed to the interpreter gbx3. The $HOME/E/OSMapA project is started and a Gambas program option s and exactly three Gambas program arguments are passed:
hans@linux:~$ gbx3 -k $HOME/E/OSMapA -- -s n -- 52.7904 11.7533 15 hans@linux:~$ gbx3 -k $HOME/E/OSMapA -- --shape j -- -30 -50 4
The value of the -s or --shape% (j (a) or n (one)) option determines whether or not to display a symbol indicating the geographic start coordinate. A detailed description of the project can be found in? chapter 5.8.2 Projects.
Figure 5.8.0.3.1: GeoMap with symbol
The use of options for a Gambas program is optional. In the next example, a Gambas project is passed to the interpreter - without using an option - but with three arguments:
hans@linux:~$ gbx3 $HOME/ColorSelectBP -- 225 110 60