set -o xtrace
set -o errexit
set -o errunset
set or shopt ?set and shopt . Both change the behavior of the shell, do much the same thing (with different arguments), and differ in their origin . The set parameters are inherited or borrowed from the parameters of other shells, while the shopt parameters shopt created in bash. $ set -o $ shopt set use a long or short syntax: $ set -o errunset $ set -e $ set +e shopt , the (more logical) -s (set) and -u (unset) flags are used to enable and disable options: $ shopt -s cdspell # <= on $ shopt -u cdspell # <= off $ shopt -s cdspell $ mkdir abcdefg $ cd abcdeg abcdefg $ cd .. cdspell saves time, literally every day.cd multiple times, you can set this option to move to the X folder if the X command does not exist. $ shopt -s autocd $ abcdefg $ cd .. $ ./abc[TAB][RETURN] cd -- ./abcdefg rm -rf * (yes, by the way, this is possible). $ shopt -s direxpand $ ./[TAB] # ... $ /full/path/to/current_working_folder $ ~/[TAB] # ... $ /full/path/to/home/folder $ $HOME/[TAB] # ... $ /full/path/to/home/folder exit . $ shopt -s checkjobs $ echo $$ 68125 # <= ID $ sleep 999 & $ exit There are running jobs. [1]+ Running sleep 999 & $ echo $$ 68125 # <= ID $ exit There are running jobs. [1]+ Running sleep 999 & $ exit $ echo $$ $ 59316 # <= ID $ shopt -s globstar $ ls ** direxpand you can quickly view everything that is lower in the hierarchy: $ shopt -s direxpand $ ls **[TAB][TAB] Display all 2033 possibilities? (y or n) $ shopt -s extglob $ touch afile bfile cfile $ ls afile bfile cfile $ ls ?(a*|b*) afile bfile $ ls !(a*|b*) cfile ? = matches zero or one occurrence of the given patterns ! = show all that does not match the specified patterns * = zero or more occurrences + = one or more occurrences @ = exactly one entry
!! and !$ .histverify option allows histverify to first see how Bash interprets a command, before it actually starts: $ shopt -s histverify $ echo !$ # <= Enter $ echo histverify # <= , histverify # <= > ). This can be a disaster if you do not have a backup.set - prohibits such rewriting. If necessary, you can bypass the protection with the operator >| : $ touch afile $ set -C $ echo something > afile -bash: afile: cannot overwrite existing file $ echo something >| afile $ Source: https://habr.com/ru/post/452522/
All Articles