Prof. dr. Razvan Daniel ZOTA Facultatea de Cibernetica ...



Seminar #2SummaryDuring the seminar #2 we worked some examples with arithmetic calculus in order to get used to the bash shell and with shell-scripts (for short, scripts).In the previous figure you have a script example for the basic arithmetical operations used in shell. Also, during the face-to-face seminar we did some examples using the modern version for arithmetic calculus in bash, using the construct $((expression)), where expression represents the arithmetical expression to be computed.For example, for computing the sum a+b, instead of using the expr command like in: sum=`expr $a + $b` , we may use sum=$((a+b)). Be careful at the syntax: when you are using the expr command in order to evaluate n arithmetic expression, you must leave spaces in front and after the operator (+, -, \*, etc.), and when you give a value to a variable using the equal sign (=) you may not leave spaces in front and after the equal sign!In order to run a script we will edit it using a text editor – here we will use pico (nano), introducing the following command as below:In this moment the program01 is opened in the pico editor (if it doesn’t exist, it will be created).After we write the source code of the program, we save it using ^O (Write Out), then we are exiting the editor with ^X (Exit). The caret sign (^) means the CTRL key from the keyboard.After we exit the editor we are back to the command prompt, where we make the program executable, using the following command: chmod +x program01Now the program can be run using the command ./program01 (the name of the program preceded by the combination ./ which specifies to the shell that the program to be run is located in the current directory). ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download