NUnix · L3 MIAGE · CM3 · 90 minutes
ISTIC · University of Rennes
2026–2027
A script saves commands so you can run them again.
Arguments let you use the same script with different inputs.
Run a script, pass arguments and store values
Bash = Bourne-Again SHell.
The name puns on Stephen Bourne, author of the earlier Unix shell sh.
We use Bash syntax in this course.
sh script.sh may select a different shell with fewer features.
| Symbol | Names you may hear |
|---|---|
| # | hash, number sign; pound sign in US usage |
| # | French: croisillon, also carré |
| ♯ | The musical sharp sign (dièse) |
#!: hash followed by bang.
The symbol’s name and its role depend on context.
Choose which commands to run with if, && and ||
0: true or false?false; echo yes print?false && echo yes print?false || true?; always continues.0, from the final executed command, true.Process a list of arguments or read a file line by line
Checking i=1
Body: 1
Checking i=2
Body: 2
Checking i=3
Body: 3
Checking i=4
| Command | Effect |
|---|---|
continue |
Skip the rest of the current iteration |
break |
Leave the current loop |
exit n |
End the script with status n |
After break, execution continues after the loop.
Group commands in functions and trace script execution
More examples and a command reference
| Variable | Meaning |
|---|---|
HOME |
Home directory |
USER |
Account name, usually set at login |
PWD, OLDPWD |
Current and previous working directories |
PATH |
Colon-separated command search directories |
SHELL |
Configured login shell, not necessarily the current shell |
TERM |
Terminal type |
HOSTNAME |
Host name in Bash |
MANPATH |
Manual search path, when explicitly set |
| Test | True when… |
|---|---|
-n "$value" |
The string is nonempty |
-z "$value" |
The string is empty |
-e "$path" |
The path exists |
-f "$path" |
It is a regular file |
-d "$path" |
It is a directory |
-s "$path" |
Its size is greater than zero |
-r, -w, -x |
Read, write or execute/search access is allowed |
$((5 / 2))?n = 3 an assignment?false?-f accept every existing directory?2 (integer division).n=3.11
2
3
5
6
7
After the loop: x=7
continue skips echo.echo runs before break.a global variable
a global variable
this is local
a global with new value
unset
outside changed.
The function's local variable is no longer in scope.
| Builtin | Use |
|---|---|
cd, pwd |
Change / report the current directory |
history |
Display command history |
exec |
Replace the shell with another program |
exit |
End the current shell |
kill |
Send a signal |
trap |
Arrange a response to a signal or shell event |
| Builtin | Use |
|---|---|
declare, readonly, local |
Define variable attributes or scope |
export, set |
Manage the environment / shell settings |
echo, read |
Print output / read input |
let, test |
Arithmetic / condition tests |
shift |
Discard leading positional parameters |
return |
End a function and report its status |