oplaTech About Teaching Archive
Oplatek's external memory

Week 7, Intro to Unix lab 2016

Content

  • Recap homework
    • sed and order of arguments a -e option
    • /dev/stdin
    • while read line; do echo $line ; done < my_input_file
  • comm, vimtutor
  • Vim
  • ps if time

Homework

  • (0 points) - recap Sed
  • (your skills) - learn Vim basics and write every homework in Vim. Start with vimtutor and you may try vimbook
  • (3 points) Write a script tree.sh [dir_path] which prints tree like structure of directories under the dir_path.
    • if dir_path argument is omitted used current working directory
    • if it is called on non existing path or file write a sensible error message and exit with exit code bigger than 0
# example output
DIR: A 
    a1.txt
    a2.txt 
    DIR: B
        b1.txt 
DIR: C
    c1.txt
    k1.txt

Bonus

  • (2 point) You have a file commands.txt where each line has following format:
    • Run COMMAND with options "OPTIONS" and arguments "ARGUMENTS"
    • Write a script which will execute the commands and hadle a nasty formated options and arguments
    • Nasty example:
      • Run ls with options "-al" and arguments "I said: \"this is nasty\""
    • Common examples:
Run ls with options "-al" and arguments "$HOME"
Run pwd with options "" and arguments ""
...