September 2018
Beginner
186 pages
4h 30m
English
In some cases, you may have a long multi-line string for input to a command in your script that you don't want to separate into another file. This is often the case with output for -h or --help options, where you don't want to store the help information outside the script.
Because quoted strings can include multiple lines, we can just use printf for this; it works fine, emitting multiple lines of output:
#!/bin/bash
case $1 in
-h|--help)
printf '%s\n' 'foo command help:
-h, --help: Show this help
-q, --quiet: Run without diagnostics
-v, --verbose: Add extra diagnostics'
exit 0
;;
esac
For commands that accept the data as input, such as cat, rather than in argument, such as printf, a different ...
Read now
Unlock full access