ELEC423 - Tutorial 04 - Handouts
ELEC423 - Tutorial 04 - Handouts
Dr Valerio Selis
V.Selis@liverpool.ac.uk
Survey results
Pyt hon: funct ions and classes
1
11/7/19
?? Question
?
/
wpa_supplicant pi
wpa_supplicant.conf halloween.txt
$ ifconfig wlan0
wlan0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a02b:f89d:3cee:8c77 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:00:00:01 txqueuelen 1000 (Ethernet)
RX packets 9458 bytes 678102 (662.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6200 bytes 1792703 (1.7 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Answer
T="/"
Ls $t
-bash: Ls: command not found
bash
cat $T/ect/wpa_supplicant
cat: /ect/wpa_supplicant: No such file or directory
exit
cd
pwd
/home/pi
ls
halloween.txt
echo ~/pi/file.txt
/home/pi/pi/file.txt
ifconfig wlan0 | grep "inet"
inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a02b:f89d:3cee:8c77 prefixlen 64 scopeid 0x20<link>
export T="~/"
bash
cat T/halloween.txt
cat: T/halloween.txt: No such file or directory
exit
2
11/7/19
Shell scripting
Shebang followed by the interpreter
#!/bin/bash
# Print Hello World to the standard output Comment
echo "Hello World"
# Assign the output of the echo command to a variable
VARIABLE=$(echo "Hello World")
# Redirect the output of the echo command to a file
echo $VARIABLE > file.txt
# Ask the user to provide an input
echo "Provide an input: "
# Store the standard input value in the “input” variable
read input
# Show the given input
Double quotation
echo "The input given is: $input"
>
$ echo "\""
"
3
11/7/19
>
$ echo "'"
'
10
Question
echo '"'"'"'"'
??
?
11
Answer
echo '"'"'"'"'
$ echo '"'"'"'"'
"'"
12
4
11/7/19
13
14
Shell scripting
Strings
15
5
11/7/19
? Question
Create a shell script that uses the output from the
traceroute command, transform it to a list and,
print out the IP count and the IP address.
traceroute to google.com (216.58.211.174), 30 hops max, 60 byte packets
1 192.168.43.1 (192.168.43.1) 2.366 ms 3.029 ms 3.128 ms
2 169.254.252.10 (169.254.252.10) 49.557 ms 49.822 ms 51.895 ms
3 172.16.220.1 (172.16.220.1) 51.596 ms 51.668 ms 51.371 ms
4 172.16.220.10 (172.16.220.10) 49.817 ms 40.445 ms 50.942 ms
5 dub08s01-in-f14.1e100.net (216.58.211.174) 50.580 ms 38.572 ms 37.716 ms
Example:
1 192.168.43.1
2 169.254.252.10
??
3 172.16.220.1
4 172.16.220.10
5 216.58.211.174
?
16
Next class?
17