Using bash options to change the behavior of scripts
Wednesday, 5 October 2022
Add Comment
Bash provides a large number of options that can be used to control the behavior of bash scripts. This post examines some of the more useful ones and explains how to display which options are in use and which are not.
Exiting when an error occurs
If you want a bash script to exit soon as it encounters an error—any error at all—in your scripts, you can add the set -o errexit option. If your script contains a syntax error, tries to read a file that doesn’t exist, attempts to append to a file when you don’t have permission to do so, or misuses a command in some way, the script will end abruptly. Here is a simple example:
#!/bin/bash set -o errexit tail NoSuchFile echo -n “Enter text to be appended> “ read txt echo $txt >> NoSuchFile
Try to run this script, and you’ll see this:
from Network World https://ift.tt/JuxTDdC
Genrerating Link.... 15 seconds.
Your Link is Ready.
0 Response to "Using bash options to change the behavior of scripts"
Post a Comment