Intro To Shell Scripting
Intro To Shell Scripting
Shell scripts
• script: A short program meant to perform a targeted task.
a series of commands combined into one executable file
1 2
1 2
• Example: A script that removes some files and then lists all files: • by launching a new shell :
bash myscript.sh
#!/bin/bash
advantage: can run without execute permission (still need read
rm output*.txt permission)
ls -l
• by running it within the current shell:
source myscript.sh
advantage: any variables defined by the script remain in this shell
(more on variables later)
3 4
3 4
1
18/08/19
5 6
7 8
2
18/08/19
9 10
9 10
11 12
3
18/08/19
13 14
13 14
these are automatically defined for you in every bash session • What happens if we clear the $PATH variable?
• Exercise : Change your attu prompt to look like this:
jimmy@mylaptop:$
See man bash for more info (search on PROMPTING)
15 16
15 16
4
18/08/19
17 18
19 20
5
18/08/19
command description
seq outputs a sequence of numbers
21 22
21 22
Exercise solution
#!/bin/bash
# Creates directories for a given number of assignments.
done
23
23