The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

Поиск:  Каталог документации

3.25. Options

Options are settings that change shell and/or script behavior.

The set command (see Section 3.9) enables options within a script. At the point in the script where you want the options to take effect, use set -o option-name or, in short form, set -option-abbrev. These two forms are equivalent.

      #!/bin/bash

      set -o verbose
      # Echoes all commands before executing.
      

      #!/bin/bash

      set -v
      # Exact same effect as above.
      

Note: To disable an option within a script, use set +o option-name or set +option-abbrev.

      #!/bin/bash

      set -o verbose
      # Command echoing on.
      command
      ...
      command

      set +o verbose
      # Command echoing off.
      command
      # Not echoed.


      set -v
      # Command echoing on.
      command
      ...
      command

      set +v
      # Command echoing off.
      command

      exit 0
      

An alternate method of enabling script options is to invoke the script with the option(s) from the command line. Some options are available only this way. Among these are -i, force script to run interactive, and -r, restricted.

      bash -v script-name
               or
      bash -o verbose script-name
      

The following is a listing of some useful options. They may be specified in either abbreviated form or by complete name.

Table 3-1. bash options

AbbreviationNameEffect
-CnoclobberPrevent overwriting of files by redirection (may be overridden by >|)
-aallexportExport all defined variables
-bnotifyNotify when jobs running in background terminate (not of much use in a script)
-fnoglobFilename expansion disabled
-pprivilegedScript runs as "suid" (caution!)
-unounsetAttempt to use undefined variable outputs error message
-vverbosePrint each command to stdout before executing it
-xxtraceSimilar to -v, but expands commands
-eerrexitAbort script at first error (when a command exits with non-zero status)
-nnoexecRead commands in script, but do not execute them
-t(none)Exit after first command
-(none)End of options flag. All other arguments are positional parameters.
--(none)Unset positional parameters. If arguments given (--arg1arg2), positional parameters set to arguments.



Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру