December 2018
Beginner
452 pages
12h 17m
English
Instead of spending any more time in this chapter not seeing actual code, we're going to jump right in and show a very simple example of a getopts script. Of course, we'll walk you through step by step so that you have the chance to understand it all.
The script we're creating does just a few simple things: if it finds the -v flag, it prints a verbose message, telling us it found the flag. If it does not find any flags, it prints nothing. If it finds any other flag, it prints an error for the user. Simple, right?
Let's take a look:
reader@ubuntu:~/scripts/chapter_15$ vim single-flag.shreader@ubuntu:~/scripts/chapter_15$ cat !$cat single-flag.sh#!/bin/bash###################################### Author: Sebastiaan Tammer