builtin

[!TIP|label:references:]

eval

eval — construct command by concatenating arguments

reference:

  • example

    • without eval:

    • with eval:

    • or with bash -c

  • example

VARIABLES
DESCRIPTION

${BASH_SOURCE[0]}

Path to the source file where the current script or function definition resides

${FUNCNAME[0]}

Name of the currently executing function

${LINENO}

Current line number within the script or function where this variable is referenced

${BASH_VERSION}

Version string of the running Bash interpreter

${BASH_LINENO[@]}

Line numbers of each function call in the call stack

${BASH_ARGV[@]}

All passed arguments (in reverse order)

${BASH_ARGC[@]}

Number of arguments received by each function in the call stack

to check the script is been sourced or run directly

PS4

[!NOTE]

  • main.sh

bash ps4
bash ps4 - 2

[!NOTE]reference:

OPTION
EXPLANATION

-a

-o allexport

-b

cause the status of terminated background jobs to be reported immediately

-e

-o errexit Exit immediately if a pipeline returns a non-zero status

-f

Disable filename expansion (globbing)

-h

-o hashall

-k

-o keyword

-m

-o monitor

-n

-o noexec

-o option-name

-p

-o privileged the $BASH_ENV and $ENV files are not processed

-t

-o onecmd

-u

-o unset treat unset variables and parameters other than the special parameters '@' or '*' as an error

-v

verbose. print shell input lines as they are read

-x

-o xtrace [debug] print commands and their arguments as they are executed

-B

-o braceexpand shell will perform brace expansion

-c

-o noclobber prevent output redirection using '>', '>&', and '<>' from overwriting existing files.

-E

-o errtrace

-H

-o histexpand

-P

do not resolve symbolic links

-T

-o functrace any trap on DEBUG and RETURN are inherited by shell functions

--

if no arguments follow this option, then the positional parameters are unset

-

signal the end of options, cause all remaining arguments to be assigned to the positional parameters

show current status

  • show on/off

  • show +o/-o

option name

option
expression

allexport

Same as -a.

braceexpand

Same as -B.

emacs

Use an emacs-style line editing interface. This also affects the editing interface used for read -e.

errexit

Same as -e.

errtrace

Same as -E.

functrace

Same as -T.

hashall

Same as -h.

histexpand

Same as -H.

history

Enable command history, as described in Bash History Facilities. This option is on by default in interactive shells.

ignoreeof

An interactive shell will not exit upon reading EOF.

keyword

Same as -k.

monitor

Same as -m.

noclobber

Same as -C.

noexec

Same as -n.

noglob

Same as -f.

nolog

Currently ignored.

notify

Same as -b.

nounset

Same as -u.

onecmd

Same as -t.

physical

Same as -P.

pipefail

If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands in the pipeline exit successfully. This option is disabled by default.

posix

Change the behavior of Bash where the default operation differs from the POSIX standard to match the standard (see Bash POSIX Mode). This is intended to make Bash behave as a strict superset of that standard.

privileged

Same as -p.

verbose

Same as -v.

vi

Use a vi-style line editing interface. This also affects the editing interface used for read -e.

xtrace

Same as -x.

set VS. shopt

  • set originates from the bourne shell (sh) and is part of the POSIX standard;

  • shopt is bourne-again shell (bash) specific

[!TIP|label:tips:]

check without output via -q

  • on

  • off

shopt

option
expression

-s

enable ( [s]et )

-u

disable ( [u]nset )

-q

suppresses normal output

-o

set -o

options

  • assoc_expand_once

  • autocd

  • cdable_vars

  • cdspell

  • checkhash

  • checkjobs

  • checkwinsize

  • cmdhist

  • compat31

  • compat32

  • compat40

  • compat41

  • compat42

  • compat43

  • compat44

  • complete_fullquote

  • direxpand

  • dirspell

  • dotglob

    • -s: * will including all .*

  • execfail

  • expand_aliases

  • extdebug

  • extglob

  • extquote

  • failglob

    • -s: show error msg and cmd not been exectued

  • force_fignore

  • globasciiranges

  • globstar

  • gnu_errfmt

  • histappend

  • histreedit

  • histverify

  • hostcomplete

  • huponexit

  • inherit_errexit

  • interactive_comments

  • lastpipe

  • lithist

  • localvar_inherit

  • localvar_unset

  • login_shell

  • mailwarn

  • no_empty_cmd_completion

  • nocaseglob

  • nocasematch

  • nullglob

  • progcomp

  • progcomp_alias

  • promptvars

  • restricted_shell

  • shift_verbose

  • sourcepath

  • xpg_echo

examples

[!NOTE|label:references:]

KEY
EXPLAIN

\C-

control prefix

\M-

meta prefix

\e

an escape character

\\

backslash

\"

", a double quotation mark

\'

', a single quote or apostrophe

\a

alert (bell)

\b

backspace

\d

delete

\f

form feed

newline

carriage return

horizontal tab

\v

vertical tab

\nnn

octal value

\xHH

hexadecimal value

EMACS COMBINATION
VI
RESULT

alt-.

-

last arg from previous command

alt-d

^[dw

delete the next word on the line

alt-backspace

^[db

delete backwards one word

ctrl-w

^[dT

delete backwards a whole word until white space/punctuation

ctrl-k

^[D

delete from the cursor to the end of the line

ctrl-u

^[d^

delete from the cursor to the start of the line

alt-f

^[E

move to the end of the word

alt-b

^[w

move to the start of the word

ctrl-e

^[$

move to the very end of the line

ctrl-a

^[^

move to the very start of the line

vi mode

[!NOTE]

hybrid mode

[!TIP|label:references:]

[!NOTE|label🎶] This is a patched version of bash 4.3.48 that adds support for custom prompt mode indicators. It also adds support for a \m prompt escape to specify where in the prompt the indicator should occur.

NUMBER
CURSOR SHAPE

0

blinking block

1

blinking block (default)

2

steady block

3

blinking underline

4

steady underline

5

blinking bar (xterm)

6

steady bar (xterm)

bash show-mode-in-prompt
bash show-mode-in-prompt

PS1

[!NOTE|label:see also:]

inputrc

bind -v for mode-string

show options

options

  • active-region-start-color

  • active-region-end-color

  • bell-style

  • bind-tty-special-chars

  • blink-matching-paren

  • colored-completion-prefix

  • colored-stats

  • comment-begin

  • completion-display-width

  • completion-ignore-case

  • completion-map-case

  • completion-prefix-display-length

  • completion-query-items

  • convert-meta

  • disable-completion

  • echo-control-characters

  • editing-mode

  • emacs-mode-string

  • enable-active-region

  • enable-bracketed-paste

  • enable-keypad

  • enable-meta-key

  • expand-tilde

  • history-preserve-point

  • history-size

  • horizontal-scroll-mode

  • input-meta

  • isearch-terminators

  • keymap

  • keyseq-timeout

  • mark-directories

  • mark-modified-lines

  • mark-symlinked-directories

  • match-hidden-files

  • menu-complete-display-prefix

  • output-meta

  • page-completions

  • print-completions-horizontally

  • revert-all-at-newline

  • show-all-if-ambiguous

  • show-all-if-unmodified

  • show-mode-in-prompt

  • skip-completed-text

  • vi-cmd-mode-string

  • vi-ins-mode-string

  • visible-stats

key bindings

example : option+&

list all names

inputrc

unbind

[!NOTE]

tips

test

[!NOTE|label:references:]

OPERATOR SYNTAX
DESCRIPTION

-a <FILE>

True if exists. (* not recommended, may collide with -a for AND)

-e <FILE>

True if exists.

-f <FILE>

True, if exists and is a regular file.

-d <FILE>

True, if exists and is a directory.

-c <FILE>

True, if exists and is a character special file.

-b <FILE>

True, if exists and is a block special file.

-p <FILE>

True, if exists and is a named pipe (FIFO).

-S <FILE>

True, if exists and is a socket file.

-L <FILE>

True, if exists and is a symbolic link.

-h <FILE>

True, if exists and is a symbolic link.

-g <FILE>

True, if exists and has sgid bit set.

-u <FILE>

True, if exists and has suid bit set.

-r <FILE>

True, if exists and is readable.

-w <FILE>

True, if exists and is writable.

-x <FILE>

True, if exists and is executable.

-s <FILE>

True, if exists and has size bigger than 0 (not empty).

-t <fd>

True, if file descriptor is open and refers to a terminal.

<FILE1> -nt <FILE2>

True, if is newer than (mtime).

<FILE1> -ot <FILE2>

True, if is older than (mtime).

<FILE1> -ef <FILE2>

True, if and refer to the same device and inode numbers.

Last updated

Was this helpful?