CHAPTER 10|bash Administration
Installing bash as the Standard Shell
#
cor@debian:~/shell/mar17$ cat 3.sh IFS=: for d in $PATH;do echo checking $d: cd $d scripts=$(file * 'shell script' |cut -d: -f1) for f in $scripts;do grep '^' $f /dev/null done done
As we mentioned earlier, if bash is started as sh (because the executable file has been renamed sh or there is a link from sh to bash) its startup behavior will change slightly to mimic the Bourne shell as closely as possible. For login shells it only attempts to read /etc/profile and ~/.profile, ignoring any other startup files like ~/.bash_profile.For interactive shells it won’t read the initialization file ~/.bashrc.
POSIX (Portable Operating System Interface) standard
bash is nearly 100% POSIX-compliant in its native mode. If you want strict POSIX adherence, you can either start bash with the --posix option, or set it from within the shell with set -o posix.
Command-Line Options
bash has several command-line options that change the behavior of and pass information to the shell. The options fall into two sets: single character options, like we’ve seen in previous chapters of this book, and multicharacter options, which are a relatively recent improvement to UNIX utilities. Table 10-1 lists all of the options
Option |
Meaning |
-c string |
Commands are read from string, if present. Any arguments after string are interpreted as |
-D |
A list of all double-quoted strings preceded by $ is printed on the standard ouput. These are the |
-i |
Interactive shell. Ignores signals TERM, INT, and QUIT. With job control in effect, TTIN, TTOU, |
-l |
Makes bash act as if invoked as a login shell. |
-o option |
Takes the same arguments as set -o. |
-O, +O shopt-option |
shopt-option is one of the shell options accepted by the shopt builtin. If shopt-option |
-s |
Reads commands from the standard input. If an argument is given to bash, this flag takes pre- |
-r |
Restricted shell. See the “Restricted Shell” section later in this chapter. |
-v |
Prints shell input lines as they’re read. |
- |
Signals the end of options and disables further option processing. Any options after this are |
--debugger |
Arranges for the debugger profile to be executed before the shell starts. Turns on extended |
--dump-strings |
Does the same as -D. |
--dump-po-strings |
Does the same as -D but the output is in the GNU gettext po (portable object) file format. |
--help |
Displays a usage message and exits. |
--login |
Makes bash act as if invoked as a login shell. Same as -l. |
--noediting |
Does not use the GNU readline library to read command lines if interactive. |
--noprofile |
Does not read the startup file /etc/profile or any of the personal initialization files. |
--norc |
Does not read the initialization file ~/.bashrc if the shell is interactive. This is on by default if |
--posix |
Changes the behavior of bash to follow the POSIX guidelines more closely where the default |
--quiet |
Shows no information on shell startup. This is the default. |
--rcfile file, --init-file file |
Executes commands read from file instead of from the initialization file ~/.bashrc if the |
--verbose |
Equivalent to -v. |
--version |
Shows the version number of this instance of bash and then exits. |
In addition to these, any set option can be used on the command line. Like shell built-ins, using a + instead of - turns an option off.
Of these options, the most useful are -i (interactive), -r (restricted), -s (read from standard input), -p (privileged), and -m (enable job control). Login shells are usually run with the -i, -s, and -m flags. We’ll look at restricted and privileged modes later in this chapter.
Environment Customization
Like the Bourne shell, bash uses the file /etc/profile for system-wide customization.When a user logs in, the shell reads and runs /etc/profile before running the user’s .bash_profile.
umask
umask, like the same command in most other shells, lets you specify the default permissions that files have when users create them. It takes the same types of arguments that the chmod command does, i.e., absolute (octal numbers) or symbolic permission values.
022 is a common umask value. This implies that when a file is created, the “most” permission it could possibly have is 755—which is the usual permission of an executable that a compiler might create. A text editor, on the other hand, might create a file with 666 permission (read and write for everyone), but the umask forces it to be 644 instead.