Lab #3 (Mar 2 – Mar 6)
- What is the difference between a scripting language and a compiled language?
- What is a regular expression (regex/regexp)? What is the difference between regex and a shell wildcard (glob)?
- What different shells are there?
- What is a variable in shell? How do you assign a value to the variable? How would you retrieve a value from the variable?
- What is the
aliascommand good for?
- What is the content of
- What is the variable
- What are the differences between running
- What is shebang (also hashbang)?
- Shell scripting.
- Environment variables.
- Shell customization and
script.shwhich prints “Hello world!” to stdout. Solution.
script.sh1) as an executable file 2) as an argument to
bash. What happens if 1)
bashis not installed on the system and 2)
bashis installed in different path? What can we do to minimize this type of problems?
#!/bin/echo? Try again running
script.shas an executable and as an argument to
set -euo pipefaildoes and why it can be useful? Give and try an example, where script with
set -ewill die as soon as an error is detected.
fact.shwith a function which computes factorial of given number. Create two variants: 1) Read input from stdin. 2) Read input from the first argument (
max.shwhich prints the maximum of given numbers. Write two variants: 1) Read numbers from stdin. 2) Read numbers from command line. Solution.
bar_plot.sh which prints horizontal bar plot. Input numbers
indicate bar height. Decide what input option is more viable for you.
$ ./bar_plots.sh 7 1 5 7: ####### 1: # 5: #####
If the largest value is greater than 60 rescale the whole plot. The
maximum number of
# is 60.
csv_sum.sh that reads CSV file on stdin. Sum all the numbers in
the given column. The column name is specified as a first argument.
$ ./csv_sum.sh points < csv_file.csv 10 $ cat csv_file.csv family_name,first_name,age,points,email Doe,Joe,22,1,joe_doe@some_mail.com Fog,Willy,38,8,ab@some_mail.com Zdepa,Pepa,10,1,pepa@some_mail.com