Respecting and applying the user's configuration

Never assume a user's choice of line-text editor ($EDITOR), visual-text editor ($VISUAL), shell ($SHELL), or web browser ($BROWSER). Instead, fall back to sensible defaults if these values are not set, using the :- form of parameter expansion:

#!/bin/bash
read -p 'Now editing your configuration file (press ENTER): '
"${VISUAL:-vi}" -- "$HOME"/.myscriptrc

The preceding script will wait for an Enter key press (well, a line entry, technically). It then starts the user's choice of visual-text editor if it's set, or defaults to vi if it's not, which should be installed on most Unix-like systems. In some circumstances, such as a script for use by beginners, a more sensible default choice might be ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.