Download presentation
Presentation is loading. Please wait.
Published byAndra Hall Modified over 5 years ago
1
Lecture 11 bash scripting overview c programming overview moving data between c and bash memory and pointers
2
Computational Physics
For many problems the basic equations determining a system's behaviour are known, but are too complex for an (even approximate) analytical solution. Chaos theory, weather prediction, quantum mechanics,fluid mechanics.....
3
Example bash script To execute: Save the text file e.g. as “script.sh”
Change the permissions on the file “chmod a+x script.sh” Run with “./script.sh”
4
Example bash script To execute: Save the text file e.g. as “script.sh”
Change the permissions on the file “chmod a+x script.sh” Run with “./script.sh”
5
Linux and shell programming
Interpretive language, each line is executed in sequence as if it was typed on the command line.. Environment can be customized e.g. $PATH and $LD_LIBRARY_PATH If an executable is not in your path you can run it with an absolute or relative path e.g. ./script.sh /home/tom/bin/script.sh
6
Help in Linux Man <command>
Lots of information on how to use a command Google is your friend, if you are stuck someone else has probably already been there
7
C programming Compiled language – More efficient than interpreted
It has become a standard language, many other languages are now based on C.
8
C program structure Include statements interpreted by cpp
Comments help you code Everything is written as a function This is what we pass to the function This is what the function returns The program always starts from the main function To use a function you have to call it Printf is a function defined in stdio.h
9
bash – C interaction Streams open by default Stdin – from the keyboard
Stdout – writes to screen by default. Stderr – writes to screen by default. These streams can be redirected “Prog 2>&1” - writes stderr to screen “Prog < file-in” – redirects file-in to use as stdin “Prog > file-out” – redirects stdout to file-out “Prog 2> stderr-out” redirect stderr to file stderr-out All other files need to be explicitly opened
10
bash – C interaction stdout stdin
Other files need to be explicitly opened
11
Memory Every time we want to store something this requires memory to be allocated. Stack - static memory “int a(100)” pre determined when we compile. Heap – dynamic, can be changed at runtime. malloc
16
Chris Kervick
17
Michael Tierney
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.