Professional Documents
Culture Documents
Linux Bash Beginners - Guide 61
Linux Bash Beginners - Guide 61
This is an example that installs a package automatically, eventhough you should normally confirm:
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Usage: $0 package."
exit 1
fi
And this is how the script runs. When prompted with the "Is this ok [y/N]" string, the script answers
"y" automatically:
[root@picon bin]# ./install.sh tuxracer
Gathering header information file(s) from server(s)
Server: Fedora Linux 2 - i386 - core
Server: Fedora Linux 2 - i386 - freshrpms
Server: JPackage 1.5 for Fedora Core 2
Server: JPackage 1.5, generic
Server: Fedora Linux 2 - i386 - updates
Finding updated packages
Downloading needed headers
Resolving dependencies
Dependencies resolved
I will do the following:
[install: tuxracer 0.61-26.i386]
Is this ok [y/N]: EnterDownloading Packages
Running test transaction:
Test transaction complete, Success!
tuxracer 100 % done 1/1
Installed: tuxracer 0.61-26.i386
Transaction(s) Complete
Summary
In this chapter, we learned how to provide user comments and how to prompt for user input. This is
usually done using the echo/read combination. We also discussed how files can be used as input
and output using file descriptors and redirection, and how this can be combined with getting input
from the user.
We stressed the importance of providing ample message for the users of our scripts. As always
when others use your scripts, it is better to give too much information than not enough. Here
documents is a type of shell construct that allows creation of lists, holding choices for the users.
This construct can also be used to execute otherwise interactive tasks in the background, without
intervention.