C2110 UNIX and programming Lesson 5 / Module 1 -1C2110 UNIX and programming Petr Kulhanek kulhanek@chemi.muni.cz National Center for Biomolecular Research, Faculty of Science Masaryk University, Kamenice 5, CZ-62500 Brno PS / 2020 Distance form of teaching: Rev1 Lesson 5 / Module 1 C2110 UNIX and programming Lesson 5 / Module 1 -2Programs vs scripts C2110 UNIX and programming Lesson 5 / Module 1 -3Programs vs Scripts source code program input outputtranslation (compilation) script interpreter input output Program is a set of machine instructions processed directly by the processor. The program is created by translatining source code of the programming language. Translated languages: C/C ++ Fortran Script is a text file containing commands and control sequences that are executed by the interpreter of used scripting language. Scripting languages: bash gnuplot awk JavaScript PHP python C2110 UNIX and programming Lesson 5 / Module 1 -4And what about JAVA? There are also different combinations of both approaches. A typical example is the Java programming language. Java bytecode interpreter JVM input output source code translation (compilation) Java Virtual Machine interpreter of Java bytecode (program compiled for the given platform - OS and HW) Java bytecode (platform independent - OS and HW) C2110 UNIX and programming Lesson 5 / Module 1 -5Programs vs Scripts, ... ➢ does not require recompilation ➢ creation self-starting code ➢ bad optimizability ➢ slower execution ➢ easy optimization ➢ fast execution ➢ must be recompiled ➢ cannot create a self-starting code source code program input outputtranslation (compilation) script interpreter input output C2110 UNIX and programming Lesson 5 / Module 1 -6Program in C language #include int main(int argc, char* argv[]) { printf("This is a program in language C!\n"); return (0); } Compilation $ gcc program.c -o program Source code Starting the program $ ./program compiler of C language the name of the file with the created program file program must have rights to be execute C2110 UNIX and programming Lesson 5 / Module 1 -7Bashi Script #!/bin/bash echo 'This is a script in Bash interpreter!' Run the script Bash interpreter file script.bash does not have to have rights to be executed Script $ bash script.bash C2110 UNIX and programming Lesson 5 / Module 1 -8Exercise 1 1. Create directories with names ukol01 and ukol02. 2. To each directory, one by one save the files program.c (ukol01) and script.bash (ukol02) from the directory ~kulhanek/Documents/C2110/Lesson05/programs. 3. Compile the source code of a program written in C. Verify that the resulting program can be run. 4. What is the size of the file containing the resulting program created by compiling the source code in C language. Open the created file in a text editor (gedit). What does the file contain? 5. Verify the functionality of the script script.bash by launching it. 6. Make a copy of the files named program2.c and script2.bash. 7. Change files program2.c and script2.bash, so that the resulting program or script prints a different text. I recommend that you save the tasks in directories according to the lessons and modules: Documents/C2110/Lesson05/M1, etc.