From: Chet Ramey Date: Sun, 16 Apr 2023 20:13:14 +0000 (-0400) Subject: new GLOBSORT variable X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d06fefb2ba59235d7eef379d6d8d40506035becf;p=thirdparty%2Fbash.git new GLOBSORT variable --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 02250cf46..574bac6a7 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -6001,3 +6001,33 @@ sig.c,sig.h not set anywhere yet), call sigpipe_handler instead of terminating the shell. Still need to make sure a sighandler is installed for SIGPIPE even if initialize_terminating_signals isn't called + + 4/14 + ---- +lib/sh/tmpfile.c + - sh_mktmpfd: add support for MT_UNLINK flag, unlinks created filename + before returning fd, fails if the unlink fails for some reason + + 4/15 + ---- +pathexp.c,pathexp.h + - globsort: support for various glob sorting criteria as defined by + the GLOBSORT variable: name, size, blocks, mtime, atime, ctime. + Default is ascending sort by name, as is traditional. Based on an + idea from Evan Gates + - setup_globsort: parse the value of the GLOBSORT variable, find + sorting type and whether or not it's ascending or descending + - noquote_glob_filename: glob_filename for programmable completion, + doesn't call quote_string_for_globbing and honors GLOBSORT, dotglob, + and globstar + +pcomplete.c + - gen_globpat_matches: call noquote_glob_filename, let that handle + all the variables and GLOB_FAILED + +variables.c + - GLOBSORT: support for special variable, call setup_globsort on + set or unset + +doc/bash.1,doc/bashref.texi + - GLOBSORT: document variable and its effects on pathname expansion diff --git a/MANIFEST b/MANIFEST index 14c2e0f1b..c6d149457 100644 --- a/MANIFEST +++ b/MANIFEST @@ -398,6 +398,7 @@ lib/readline/examples/rl.c f lib/readline/examples/rlcat.c f lib/readline/examples/Inputrc f lib/sh/Makefile.in f +lib/sh/anonfile.c f lib/sh/casemod.c f lib/sh/clktck.c f lib/sh/clock.c f @@ -444,8 +445,10 @@ lib/sh/strerror.c f lib/sh/strftime.c f lib/sh/stringlist.c f lib/sh/stringvec.c f +lib/sh/strlcpy.c f lib/sh/strnlen.c f lib/sh/strpbrk.c f +lib/sh/strscpy.c f lib/sh/strstr.c f lib/sh/strtod.c f lib/sh/strtoimax.c f diff --git a/Makefile.in b/Makefile.in index ab45e1a55..115c6a210 100644 --- a/Makefile.in +++ b/Makefile.in @@ -236,7 +236,7 @@ SHLIB_SOURCE = ${SH_LIBSRC}/clktck.c ${SH_LIBSRC}/getcwd.c \ ${SH_LIBSRC}/eaccess.c ${SH_LIBSRC}/wcsdup.c \ ${SH_LIBSRC}/zmapfd.c ${SH_LIBSRC}/fpurge.c \ ${SH_LIBSRC}/zgetline.c ${SH_LIBSRC}/mbscmp.c \ - ${SH_LIBSRC}/mbsncmp.c \ + ${SH_LIBSRC}/mbsncmp.c ${SH_LIBSRC}/anonfile.c \ ${SH_LIBSRC}/casemod.c ${SH_LIBSRC}/uconvert.c \ ${SH_LIBSRC}/ufuncs.c ${SH_LIBSRC}/dprintf.c \ ${SH_LIBSRC}/input_avail.c ${SH_LIBSRC}/mbscasecmp.c \ @@ -244,7 +244,8 @@ SHLIB_SOURCE = ${SH_LIBSRC}/clktck.c ${SH_LIBSRC}/getcwd.c \ ${SH_LIBSRC}/wcswidth.c ${SH_LIBSRC}/wcsnwidth.c \ ${SH_LIBSRC}/shmbchar.c ${SH_LIBSRC}/utf8.c \ ${SH_LIBSRC}/random.c ${SH_LIBSRC}/gettimeofday.c \ - ${SH_LIBSRC}/timers.c ${SH_LIBSRC}/strvis.c + ${SH_LIBSRC}/timers.c ${SH_LIBSRC}/strvis.c \ + ${SH_LIBSRC}/strlcpy.c ${SH_LIBSRC}/strscpy.c SHLIB_LIB = -lsh SHLIB_LIBNAME = libsh.a diff --git a/config-top.h b/config-top.h index 6e87a7ced..62b67096f 100644 --- a/config-top.h +++ b/config-top.h @@ -69,7 +69,7 @@ the Posix.2 confstr () function, or CS_PATH define are not present. */ #ifndef STANDARD_UTILS_PATH #define STANDARD_UTILS_PATH \ - "/bin:/usr/bin:/sbin:/usr/sbin:/etc:/usr/etc" + "/bin:/usr/bin:/sbin:/usr/sbin" #endif /* The default path for enable -f */ diff --git a/config.h.in b/config.h.in index 1681f8c34..b5007fed0 100644 --- a/config.h.in +++ b/config.h.in @@ -750,6 +750,9 @@ /* Define if you have the mbsrtowcs function. */ #undef HAVE_MBSRTOWCS +/* Define if you have the memfd_create function. */ +#undef HAVE_MEMFD_CREATE + /* Define if you have the memmove function. */ #undef HAVE_MEMMOVE @@ -828,6 +831,12 @@ #undef HAVE_SETRESUID #undef HAVE_DECL_SETRESUID +/* Define if you have the shm_open function. */ +#undef HAVE_SHM_OPEN + +/* Define if you have the shm_mkstemp function. */ +#undef HAVE_SHM_MKSTEMP + /* Define if you have the setvbuf function. */ #undef HAVE_SETVBUF @@ -861,6 +870,9 @@ /* Define if you have the strftime function. */ #undef HAVE_STRFTIME +/* Define if you have the strlcat function. */ +#undef HAVE_STRLCAT + /* Define if you have the strnlen function. */ #undef HAVE_STRNLEN diff --git a/configure b/configure index 74dc82e80..f0d841f9a 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac for Bash 5.2, version 5.049. +# From configure.ac for Bash 5.2, version 5.050. # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.71 for bash 5.2-maint. # @@ -15305,6 +15305,33 @@ then : fi +ac_fn_c_check_func "$LINENO" "strlcat" "ac_cv_func_strlcat" +if test "x$ac_cv_func_strlcat" = xyes +then : + printf "%s\n" "#define HAVE_STRLCAT 1" >>confdefs.h + +fi + + +ac_fn_c_check_func "$LINENO" "memfd_create" "ac_cv_func_memfd_create" +if test "x$ac_cv_func_memfd_create" = xyes +then : + printf "%s\n" "#define HAVE_MEMFD_CREATE 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "shm_open" "ac_cv_func_shm_open" +if test "x$ac_cv_func_shm_open" = xyes +then : + printf "%s\n" "#define HAVE_SHM_OPEN 1" >>confdefs.h + +fi +ac_fn_c_check_func "$LINENO" "shm_mkstemp" "ac_cv_func_shm_mkstemp" +if test "x$ac_cv_func_shm_mkstemp" = xyes +then : + printf "%s\n" "#define HAVE_SHM_MKSTEMP 1" >>confdefs.h + +fi + ac_fn_c_check_func "$LINENO" "getcwd" "ac_cv_func_getcwd" if test "x$ac_cv_func_getcwd" = xyes @@ -15546,6 +15573,20 @@ esac fi +ac_fn_c_check_func "$LINENO" "strlcpy" "ac_cv_func_strlcpy" +if test "x$ac_cv_func_strlcpy" = xyes +then : + printf "%s\n" "#define HAVE_STRLCPY 1" >>confdefs.h + +else $as_nop + case " $LIBOBJS " in + *" strlcpy.$ac_objext "* ) ;; + *) LIBOBJS="$LIBOBJS strlcpy.$ac_objext" + ;; +esac + +fi + ac_fn_c_check_header_compile "$LINENO" "libaudit.h" "ac_cv_header_libaudit_h" "$ac_includes_default" if test "x$ac_cv_header_libaudit_h" = xyes diff --git a/configure.ac b/configure.ac index 68c38c09d..bcd7f040d 100644 --- a/configure.ac +++ b/configure.ac @@ -21,7 +21,7 @@ dnl Process this file with autoconf to produce a configure script. # You should have received a copy of the GNU General Public License # along with this program. If not, see . -AC_REVISION([for Bash 5.2, version 5.049])dnl +AC_REVISION([for Bash 5.2, version 5.050])dnl define(bashvers, 5.2) define(relstatus, maint) @@ -857,6 +857,9 @@ AC_CHECK_FUNCS(isascii isblank isgraph isprint isspace isxdigit) AC_CHECK_FUNCS(getpwent getpwnam getpwuid) AC_CHECK_FUNCS(mkstemp mkdtemp) AC_CHECK_FUNCS(arc4random) +AC_CHECK_FUNCS(strlcat) + +AC_CHECK_FUNCS(memfd_create shm_open shm_mkstemp) AC_REPLACE_FUNCS(getcwd memset) AC_REPLACE_FUNCS(strcasecmp strcasestr strerror strftime strnlen strpbrk strstr) @@ -864,6 +867,7 @@ AC_REPLACE_FUNCS(strtod strtol strtoul strtoll strtoull strtoumax) AC_REPLACE_FUNCS(dprintf) AC_REPLACE_FUNCS(strchrnul) AC_REPLACE_FUNCS(strdup) +AC_REPLACE_FUNCS(strlcpy) AC_CHECK_HEADERS(libaudit.h) AC_CHECK_DECLS([AUDIT_USER_TTY],,, [[#include ]]) diff --git a/doc/bash.0 b/doc/bash.0 index b8e32b75b..5e635134c 100644 --- a/doc/bash.0 +++ b/doc/bash.0 @@ -1193,197 +1193,214 @@ PPAARRAAMMEETTEERRSS names to be ignored by pathname expansion. If a file name matched by a pathname expansion pattern also matches one of the patterns in GGLLOOBBIIGGNNOORREE, it is removed from the list of matches. + GGLLOOBBSSOORRTT + Control how the results of pathname expansion are sorted. The + value of this variable specifies the sort criteria and sort or- + der for the results of pathname expansion. If this variable is + unset or set to the null string, pathname expansion uses the + historial behavior of sorting by name. If set, a valid value + begins with an optional _+, which is ignored, or _-, which re- + verses the sort order from ascending to descending, followed by + a sort specifier. The valid sort specifiers are _n_a_m_e, _s_i_z_e, + _m_t_i_m_e, _a_t_i_m_e, _c_t_i_m_e, and _b_l_o_c_k_s, which sort the files on name, + file size, modification time, access time, inode change time, + and number of blocks, respectively. For example, a value of + --mmttiimmee sorts the results in descending order by modification + time (newest first). If the sort specifier is missing, it de- + faults to _n_a_m_e, so a value of _+ is equivalent to the null + string, and a value of _- sorts by name in descending order. Any + invalid value restores the historical sorting behavior. HHIISSTTCCOONNTTRROOLL - A colon-separated list of values controlling how commands are - saved on the history list. If the list of values includes _i_g_- - _n_o_r_e_s_p_a_c_e, lines which begin with a ssppaaccee character are not - saved in the history list. A value of _i_g_n_o_r_e_d_u_p_s causes lines + A colon-separated list of values controlling how commands are + saved on the history list. If the list of values includes _i_g_- + _n_o_r_e_s_p_a_c_e, lines which begin with a ssppaaccee character are not + saved in the history list. A value of _i_g_n_o_r_e_d_u_p_s causes lines matching the previous history entry to not be saved. A value of _i_g_n_o_r_e_b_o_t_h is shorthand for _i_g_n_o_r_e_s_p_a_c_e and _i_g_n_o_r_e_d_u_p_s. A value of _e_r_a_s_e_d_u_p_s causes all previous lines matching the current line - to be removed from the history list before that line is saved. - Any value not in the above list is ignored. If HHIISSTTCCOONNTTRROOLL is - unset, or does not include a valid value, all lines read by the + to be removed from the history list before that line is saved. + Any value not in the above list is ignored. If HHIISSTTCCOONNTTRROOLL is + unset, or does not include a valid value, all lines read by the shell parser are saved on the history list, subject to the value - of HHIISSTTIIGGNNOORREE. The second and subsequent lines of a multi-line - compound command are not tested, and are added to the history + of HHIISSTTIIGGNNOORREE. The second and subsequent lines of a multi-line + compound command are not tested, and are added to the history regardless of the value of HHIISSTTCCOONNTTRROOLL. HHIISSTTFFIILLEE The name of the file in which command history is saved (see HHIISS-- - TTOORRYY below). The default value is _~_/_._b_a_s_h___h_i_s_t_o_r_y. If unset, + TTOORRYY below). The default value is _~_/_._b_a_s_h___h_i_s_t_o_r_y. If unset, the command history is not saved when a shell exits. HHIISSTTFFIILLEESSIIZZEE The maximum number of lines contained in the history file. When - this variable is assigned a value, the history file is trun- - cated, if necessary, to contain no more than that number of - lines by removing the oldest entries. The history file is also - truncated to this size after writing it when a shell exits. If - the value is 0, the history file is truncated to zero size. - Non-numeric values and numeric values less than zero inhibit - truncation. The shell sets the default value to the value of + this variable is assigned a value, the history file is trun- + cated, if necessary, to contain no more than that number of + lines by removing the oldest entries. The history file is also + truncated to this size after writing it when a shell exits. If + the value is 0, the history file is truncated to zero size. + Non-numeric values and numeric values less than zero inhibit + truncation. The shell sets the default value to the value of HHIISSTTSSIIZZEE after reading any startup files. HHIISSTTIIGGNNOORREE - A colon-separated list of patterns used to decide which command - lines should be saved on the history list. Each pattern is an- - chored at the beginning of the line and must match the complete - line (no implicit `**' is appended). Each pattern is tested - against the line after the checks specified by HHIISSTTCCOONNTTRROOLL are + A colon-separated list of patterns used to decide which command + lines should be saved on the history list. Each pattern is an- + chored at the beginning of the line and must match the complete + line (no implicit `**' is appended). Each pattern is tested + against the line after the checks specified by HHIISSTTCCOONNTTRROOLL are applied. In addition to the normal shell pattern matching char- - acters, `&&' matches the previous history line. `&&' may be es- - caped using a backslash; the backslash is removed before at- - tempting a match. The second and subsequent lines of a multi- - line compound command are not tested, and are added to the his- - tory regardless of the value of HHIISSTTIIGGNNOORREE. The pattern match- + acters, `&&' matches the previous history line. `&&' may be es- + caped using a backslash; the backslash is removed before at- + tempting a match. The second and subsequent lines of a multi- + line compound command are not tested, and are added to the his- + tory regardless of the value of HHIISSTTIIGGNNOORREE. The pattern match- ing honors the setting of the eexxttgglloobb shell option. HHIISSTTSSIIZZEE - The number of commands to remember in the command history (see - HHIISSTTOORRYY below). If the value is 0, commands are not saved in + The number of commands to remember in the command history (see + HHIISSTTOORRYY below). If the value is 0, commands are not saved in the history list. Numeric values less than zero result in every - command being saved on the history list (there is no limit). - The shell sets the default value to 500 after reading any + command being saved on the history list (there is no limit). + The shell sets the default value to 500 after reading any startup files. HHIISSTTTTIIMMEEFFOORRMMAATT - If this variable is set and not null, its value is used as a + If this variable is set and not null, its value is used as a format string for _s_t_r_f_t_i_m_e(3) to print the time stamp associated - with each history entry displayed by the hhiissttoorryy builtin. If - this variable is set, time stamps are written to the history - file so they may be preserved across shell sessions. This uses - the history comment character to distinguish timestamps from + with each history entry displayed by the hhiissttoorryy builtin. If + this variable is set, time stamps are written to the history + file so they may be preserved across shell sessions. This uses + the history comment character to distinguish timestamps from other history lines. HHOOMMEE The home directory of the current user; the default argument for the ccdd builtin command. The value of this variable is also used when performing tilde expansion. HHOOSSTTFFIILLEE - Contains the name of a file in the same format as _/_e_t_c_/_h_o_s_t_s + Contains the name of a file in the same format as _/_e_t_c_/_h_o_s_t_s that should be read when the shell needs to complete a hostname. - The list of possible hostname completions may be changed while - the shell is running; the next time hostname completion is at- - tempted after the value is changed, bbaasshh adds the contents of - the new file to the existing list. If HHOOSSTTFFIILLEE is set, but has - no value, or does not name a readable file, bbaasshh attempts to - read _/_e_t_c_/_h_o_s_t_s to obtain the list of possible hostname comple- + The list of possible hostname completions may be changed while + the shell is running; the next time hostname completion is at- + tempted after the value is changed, bbaasshh adds the contents of + the new file to the existing list. If HHOOSSTTFFIILLEE is set, but has + no value, or does not name a readable file, bbaasshh attempts to + read _/_e_t_c_/_h_o_s_t_s to obtain the list of possible hostname comple- tions. When HHOOSSTTFFIILLEE is unset, the hostname list is cleared. IIFFSS The _I_n_t_e_r_n_a_l _F_i_e_l_d _S_e_p_a_r_a_t_o_r that is used for word splitting af- - ter expansion and to split lines into words with the rreeaadd + ter expansion and to split lines into words with the rreeaadd builtin command. The default value is ``''. IIGGNNOORREEEEOOFF Controls the action of an interactive shell on receipt of an EEOOFF character as the sole input. If set, the value is the number of - consecutive EEOOFF characters which must be typed as the first - characters on an input line before bbaasshh exits. If the variable - exists but does not have a numeric value, or has no value, the - default value is 10. If it does not exist, EEOOFF signifies the + consecutive EEOOFF characters which must be typed as the first + characters on an input line before bbaasshh exits. If the variable + exists but does not have a numeric value, or has no value, the + default value is 10. If it does not exist, EEOOFF signifies the end of input to the shell. IINNPPUUTTRRCC - The filename for the rreeaaddlliinnee startup file, overriding the de- + The filename for the rreeaaddlliinnee startup file, overriding the de- fault of _~_/_._i_n_p_u_t_r_c (see RREEAADDLLIINNEE below). IINNSSIIDDEE__EEMMAACCSS - If this variable appears in the environment when the shell - starts, bbaasshh assumes that it is running inside an Emacs shell - buffer and may disable line editing, depending on the value of + If this variable appears in the environment when the shell + starts, bbaasshh assumes that it is running inside an Emacs shell + buffer and may disable line editing, depending on the value of TTEERRMM. - LLAANNGG Used to determine the locale category for any category not + LLAANNGG Used to determine the locale category for any category not specifically selected with a variable starting with LLCC__. - LLCC__AALLLL This variable overrides the value of LLAANNGG and any other LLCC__ + LLCC__AALLLL This variable overrides the value of LLAANNGG and any other LLCC__ variable specifying a locale category. LLCC__CCOOLLLLAATTEE - This variable determines the collation order used when sorting - the results of pathname expansion, and determines the behavior - of range expressions, equivalence classes, and collating se- + This variable determines the collation order used when sorting + the results of pathname expansion, and determines the behavior + of range expressions, equivalence classes, and collating se- quences within pathname expansion and pattern matching. LLCC__CCTTYYPPEE - This variable determines the interpretation of characters and - the behavior of character classes within pathname expansion and + This variable determines the interpretation of characters and + the behavior of character classes within pathname expansion and pattern matching. LLCC__MMEESSSSAAGGEESS - This variable determines the locale used to translate double- + This variable determines the locale used to translate double- quoted strings preceded by a $$. LLCC__NNUUMMEERRIICC - This variable determines the locale category used for number + This variable determines the locale category used for number formatting. LLCC__TTIIMMEE - This variable determines the locale category used for data and + This variable determines the locale category used for data and time formatting. - LLIINNEESS Used by the sseelleecctt compound command to determine the column - length for printing selection lists. Automatically set if the - cchheecckkwwiinnssiizzee option is enabled or in an interactive shell upon + LLIINNEESS Used by the sseelleecctt compound command to determine the column + length for printing selection lists. Automatically set if the + cchheecckkwwiinnssiizzee option is enabled or in an interactive shell upon receipt of a SSIIGGWWIINNCCHH. - MMAAIILL If this parameter is set to a file or directory name and the - MMAAIILLPPAATTHH variable is not set, bbaasshh informs the user of the ar- + MMAAIILL If this parameter is set to a file or directory name and the + MMAAIILLPPAATTHH variable is not set, bbaasshh informs the user of the ar- rival of mail in the specified file or Maildir-format directory. MMAAIILLCCHHEECCKK - Specifies how often (in seconds) bbaasshh checks for mail. The de- - fault is 60 seconds. When it is time to check for mail, the - shell does so before displaying the primary prompt. If this - variable is unset, or set to a value that is not a number + Specifies how often (in seconds) bbaasshh checks for mail. The de- + fault is 60 seconds. When it is time to check for mail, the + shell does so before displaying the primary prompt. If this + variable is unset, or set to a value that is not a number greater than or equal to zero, the shell disables mail checking. MMAAIILLPPAATTHH A colon-separated list of filenames to be checked for mail. The message to be printed when mail arrives in a particular file may - be specified by separating the filename from the message with a - `?'. When used in the text of the message, $$__ expands to the + be specified by separating the filename from the message with a + `?'. When used in the text of the message, $$__ expands to the name of the current mailfile. Example: MMAAIILLPPAATTHH='/var/mail/bfox?"You have mail":~/shell-mail?"$_ has mail!"' - BBaasshh can be configured to supply a default value for this vari- - able (there is no value by default), but the location of the + BBaasshh can be configured to supply a default value for this vari- + able (there is no value by default), but the location of the user mail files that it uses is system dependent (e.g., /var/mail/$$UUSSEERR). OOPPTTEERRRR If set to the value 1, bbaasshh displays error messages generated by - the ggeettooppttss builtin command (see SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS below). - OOPPTTEERRRR is initialized to 1 each time the shell is invoked or a + the ggeettooppttss builtin command (see SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS below). + OOPPTTEERRRR is initialized to 1 each time the shell is invoked or a shell script is executed. - PPAATTHH The search path for commands. It is a colon-separated list of - directories in which the shell looks for commands (see CCOOMMMMAANNDD - EEXXEECCUUTTIIOONN below). A zero-length (null) directory name in the + PPAATTHH The search path for commands. It is a colon-separated list of + directories in which the shell looks for commands (see CCOOMMMMAANNDD + EEXXEECCUUTTIIOONN below). A zero-length (null) directory name in the value of PPAATTHH indicates the current directory. A null directory - name may appear as two adjacent colons, or as an initial or - trailing colon. The default path is system-dependent, and is + name may appear as two adjacent colons, or as an initial or + trailing colon. The default path is system-dependent, and is set by the administrator who installs bbaasshh. A common value is ``/usr/local/bin:/usr/lo- cal/sbin:/usr/bin:/usr/sbin:/bin:/sbin''. PPOOSSIIXXLLYY__CCOORRRREECCTT - If this variable is in the environment when bbaasshh starts, the - shell enters _p_o_s_i_x _m_o_d_e before reading the startup files, as if - the ----ppoossiixx invocation option had been supplied. If it is set - while the shell is running, bbaasshh enables _p_o_s_i_x _m_o_d_e, as if the - command _s_e_t _-_o _p_o_s_i_x had been executed. When the shell enters + If this variable is in the environment when bbaasshh starts, the + shell enters _p_o_s_i_x _m_o_d_e before reading the startup files, as if + the ----ppoossiixx invocation option had been supplied. If it is set + while the shell is running, bbaasshh enables _p_o_s_i_x _m_o_d_e, as if the + command _s_e_t _-_o _p_o_s_i_x had been executed. When the shell enters _p_o_s_i_x _m_o_d_e, it sets this variable if it was not already set. PPRROOMMPPTT__CCOOMMMMAANNDD - If this variable is set, and is an array, the value of each set - element is executed as a command prior to issuing each primary - prompt. If this is set but not an array variable, its value is + If this variable is set, and is an array, the value of each set + element is executed as a command prior to issuing each primary + prompt. If this is set but not an array variable, its value is used as a command to execute instead. PPRROOMMPPTT__DDIIRRTTRRIIMM - If set to a number greater than zero, the value is used as the + If set to a number greater than zero, the value is used as the number of trailing directory components to retain when expanding - the \\ww and \\WW prompt string escapes (see PPRROOMMPPTTIINNGG below). + the \\ww and \\WW prompt string escapes (see PPRROOMMPPTTIINNGG below). Characters removed are replaced with an ellipsis. - PPSS00 The value of this parameter is expanded (see PPRROOMMPPTTIINNGG below) - and displayed by interactive shells after reading a command and + PPSS00 The value of this parameter is expanded (see PPRROOMMPPTTIINNGG below) + and displayed by interactive shells after reading a command and before the command is executed. - PPSS11 The value of this parameter is expanded (see PPRROOMMPPTTIINNGG below) - and used as the primary prompt string. The default value is + PPSS11 The value of this parameter is expanded (see PPRROOMMPPTTIINNGG below) + and used as the primary prompt string. The default value is ``\\ss--\\vv\\$$ ''. - PPSS22 The value of this parameter is expanded as with PPSS11 and used as + PPSS22 The value of this parameter is expanded as with PPSS11 and used as the secondary prompt string. The default is ``>> ''. PPSS33 The value of this parameter is used as the prompt for the sseelleecctt command (see SSHHEELLLL GGRRAAMMMMAARR above). - PPSS44 The value of this parameter is expanded as with PPSS11 and the + PPSS44 The value of this parameter is expanded as with PPSS11 and the value is printed before each command bbaasshh displays during an ex- ecution trace. The first character of the expanded value of PPSS44 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is ``++ ''. - SSHHEELLLL This variable expands to the full pathname to the shell. If it - is not set when the shell starts, bbaasshh assigns to it the full + SSHHEELLLL This variable expands to the full pathname to the shell. If it + is not set when the shell starts, bbaasshh assigns to it the full pathname of the current user's login shell. TTIIMMEEFFOORRMMAATT - The value of this parameter is used as a format string specify- - ing how the timing information for pipelines prefixed with the - ttiimmee reserved word should be displayed. The %% character intro- - duces an escape sequence that is expanded to a time value or - other information. The escape sequences and their meanings are + The value of this parameter is used as a format string specify- + ing how the timing information for pipelines prefixed with the + ttiimmee reserved word should be displayed. The %% character intro- + duces an escape sequence that is expanded to a time value or + other information. The escape sequences and their meanings are as follows; the braces denote optional portions. %%%% A literal %%. %%[[_p]][[ll]]RR The elapsed time in seconds. @@ -1391,77 +1408,77 @@ PPAARRAAMMEETTEERRSS %%[[_p]][[ll]]SS The number of CPU seconds spent in system mode. %%PP The CPU percentage, computed as (%U + %S) / %R. - The optional _p is a digit specifying the _p_r_e_c_i_s_i_o_n, the number + The optional _p is a digit specifying the _p_r_e_c_i_s_i_o_n, the number of fractional digits after a decimal point. A value of 0 causes no decimal point or fraction to be output. At most three places - after the decimal point may be specified; values of _p greater - than 3 are changed to 3. If _p is not specified, the value 3 is + after the decimal point may be specified; values of _p greater + than 3 are changed to 3. If _p is not specified, the value 3 is used. - The optional ll specifies a longer format, including minutes, of - the form _M_Mm_S_S._F_Fs. The value of _p determines whether or not + The optional ll specifies a longer format, including minutes, of + the form _M_Mm_S_S._F_Fs. The value of _p determines whether or not the fraction is included. - If this variable is not set, bbaasshh acts as if it had the value - $$''\\nnrreeaall\\tt%%33llRR\\nnuusseerr\\tt%%33llUU\\nnssyyss\\tt%%33llSS''. If the value is null, + If this variable is not set, bbaasshh acts as if it had the value + $$''\\nnrreeaall\\tt%%33llRR\\nnuusseerr\\tt%%33llUU\\nnssyyss\\tt%%33llSS''. If the value is null, no timing information is displayed. A trailing newline is added when the format string is displayed. TTMMOOUUTT If set to a value greater than zero, TTMMOOUUTT is treated as the de- - fault timeout for the rreeaadd builtin. The sseelleecctt command termi- + fault timeout for the rreeaadd builtin. The sseelleecctt command termi- nates if input does not arrive after TTMMOOUUTT seconds when input is - coming from a terminal. In an interactive shell, the value is + coming from a terminal. In an interactive shell, the value is interpreted as the number of seconds to wait for a line of input after issuing the primary prompt. BBaasshh terminates after waiting - for that number of seconds if a complete line of input does not + for that number of seconds if a complete line of input does not arrive. - TTMMPPDDIIRR If set, bbaasshh uses its value as the name of a directory in which + TTMMPPDDIIRR If set, bbaasshh uses its value as the name of a directory in which bbaasshh creates temporary files for the shell's use. aauuttoo__rreessuummee This variable controls how the shell interacts with the user and - job control. If this variable is set, single word simple com- + job control. If this variable is set, single word simple com- mands without redirections are treated as candidates for resump- tion of an existing stopped job. There is no ambiguity allowed; - if there is more than one job beginning with the string typed, - the job most recently accessed is selected. The _n_a_m_e of a - stopped job, in this context, is the command line used to start - it. If set to the value _e_x_a_c_t, the string supplied must match - the name of a stopped job exactly; if set to _s_u_b_s_t_r_i_n_g, the - string supplied needs to match a substring of the name of a - stopped job. The _s_u_b_s_t_r_i_n_g value provides functionality analo- - gous to the %%?? job identifier (see JJOOBB CCOONNTTRROOLL below). If set - to any other value, the supplied string must be a prefix of a + if there is more than one job beginning with the string typed, + the job most recently accessed is selected. The _n_a_m_e of a + stopped job, in this context, is the command line used to start + it. If set to the value _e_x_a_c_t, the string supplied must match + the name of a stopped job exactly; if set to _s_u_b_s_t_r_i_n_g, the + string supplied needs to match a substring of the name of a + stopped job. The _s_u_b_s_t_r_i_n_g value provides functionality analo- + gous to the %%?? job identifier (see JJOOBB CCOONNTTRROOLL below). If set + to any other value, the supplied string must be a prefix of a stopped job's name; this provides functionality analogous to the %%_s_t_r_i_n_g job identifier. hhiissttcchhaarrss - The two or three characters which control history expansion and + The two or three characters which control history expansion and tokenization (see HHIISSTTOORRYY EEXXPPAANNSSIIOONN below). The first character - is the _h_i_s_t_o_r_y _e_x_p_a_n_s_i_o_n character, the character which signals - the start of a history expansion, normally `!!'. The second - character is the _q_u_i_c_k _s_u_b_s_t_i_t_u_t_i_o_n character, which is used as - shorthand for re-running the previous command entered, substi- - tuting one string for another in the command. The default is - `^^'. The optional third character is the character which indi- - cates that the remainder of the line is a comment when found as - the first character of a word, normally `##'. The history com- + is the _h_i_s_t_o_r_y _e_x_p_a_n_s_i_o_n character, the character which signals + the start of a history expansion, normally `!!'. The second + character is the _q_u_i_c_k _s_u_b_s_t_i_t_u_t_i_o_n character, which is used as + shorthand for re-running the previous command entered, substi- + tuting one string for another in the command. The default is + `^^'. The optional third character is the character which indi- + cates that the remainder of the line is a comment when found as + the first character of a word, normally `##'. The history com- ment character causes history substitution to be skipped for the - remaining words on the line. It does not necessarily cause the + remaining words on the line. It does not necessarily cause the shell parser to treat the rest of the line as a comment. AArrrraayyss - BBaasshh provides one-dimensional indexed and associative array variables. - Any variable may be used as an indexed array; the ddeeccllaarree builtin will - explicitly declare an array. There is no maximum limit on the size of - an array, nor any requirement that members be indexed or assigned con- - tiguously. Indexed arrays are referenced using integers (including + BBaasshh provides one-dimensional indexed and associative array variables. + Any variable may be used as an indexed array; the ddeeccllaarree builtin will + explicitly declare an array. There is no maximum limit on the size of + an array, nor any requirement that members be indexed or assigned con- + tiguously. Indexed arrays are referenced using integers (including arithmetic expressions) and are zero-based; associative arrays are ref- erenced using arbitrary strings. Unless otherwise noted, indexed array indices must be non-negative integers. - An indexed array is created automatically if any variable is assigned + An indexed array is created automatically if any variable is assigned to using the syntax _n_a_m_e[_s_u_b_s_c_r_i_p_t]=_v_a_l_u_e. The _s_u_b_s_c_r_i_p_t is treated as an arithmetic expression that must evaluate to a number. To explicitly - declare an indexed array, use ddeeccllaarree --aa _n_a_m_e (see SSHHEELLLL BBUUIILLTTIINN CCOOMM-- - MMAANNDDSS below). ddeeccllaarree --aa _n_a_m_e[[_s_u_b_s_c_r_i_p_t]] is also accepted; the _s_u_b_- + declare an indexed array, use ddeeccllaarree --aa _n_a_m_e (see SSHHEELLLL BBUUIILLTTIINN CCOOMM-- + MMAANNDDSS below). ddeeccllaarree --aa _n_a_m_e[[_s_u_b_s_c_r_i_p_t]] is also accepted; the _s_u_b_- _s_c_r_i_p_t is ignored. Associative arrays are created using ddeeccllaarree --AA _n_a_m_e. @@ -1469,159 +1486,159 @@ PPAARRAAMMEETTEERRSS Attributes may be specified for an array variable using the ddeeccllaarree and rreeaaddoonnllyy builtins. Each attribute applies to all members of an array. - Arrays are assigned to using compound assignments of the form - _n_a_m_e=((value_1 ... value_n)), where each _v_a_l_u_e may be of the form [_s_u_b_- - _s_c_r_i_p_t]=_s_t_r_i_n_g. Indexed array assignments do not require anything but - _s_t_r_i_n_g. Each _v_a_l_u_e in the list is expanded using the shell expansions + Arrays are assigned to using compound assignments of the form + _n_a_m_e=((value_1 ... value_n)), where each _v_a_l_u_e may be of the form [_s_u_b_- + _s_c_r_i_p_t]=_s_t_r_i_n_g. Indexed array assignments do not require anything but + _s_t_r_i_n_g. Each _v_a_l_u_e in the list is expanded using the shell expansions described below under EEXXPPAANNSSIIOONN, but _v_a_l_u_es that are valid variable as- signments including the brackets and subscript do not undergo brace ex- - pansion and word splitting, as with individual variable assignments. - When assigning to indexed arrays, if the optional brackets and sub- - script are supplied, that index is assigned to; otherwise the index of - the element assigned is the last index assigned to by the statement + pansion and word splitting, as with individual variable assignments. + When assigning to indexed arrays, if the optional brackets and sub- + script are supplied, that index is assigned to; otherwise the index of + the element assigned is the last index assigned to by the statement plus one. Indexing starts at zero. When assigning to an associative array, the words in a compound assign- - ment may be either assignment statements, for which the subscript is - required, or a list of words that is interpreted as a sequence of al- - ternating keys and values: _n_a_m_e=(( _k_e_y_1 _v_a_l_u_e_1 _k_e_y_2 _v_a_l_u_e_2 ...)). These - are treated identically to _n_a_m_e=(( [_k_e_y_1]=_v_a_l_u_e_1 [_k_e_y_2]=_v_a_l_u_e_2 ...)). - The first word in the list determines how the remaining words are in- - terpreted; all assignments in a list must be of the same type. When - using key/value pairs, the keys may not be missing or empty; a final + ment may be either assignment statements, for which the subscript is + required, or a list of words that is interpreted as a sequence of al- + ternating keys and values: _n_a_m_e=(( _k_e_y_1 _v_a_l_u_e_1 _k_e_y_2 _v_a_l_u_e_2 ...)). These + are treated identically to _n_a_m_e=(( [_k_e_y_1]=_v_a_l_u_e_1 [_k_e_y_2]=_v_a_l_u_e_2 ...)). + The first word in the list determines how the remaining words are in- + terpreted; all assignments in a list must be of the same type. When + using key/value pairs, the keys may not be missing or empty; a final missing value is treated like the empty string. - This syntax is also accepted by the ddeeccllaarree builtin. Individual array - elements may be assigned to using the _n_a_m_e[_s_u_b_s_c_r_i_p_t]=_v_a_l_u_e syntax in- - troduced above. When assigning to an indexed array, if _n_a_m_e is sub- - scripted by a negative number, that number is interpreted as relative - to one greater than the maximum index of _n_a_m_e, so negative indices + This syntax is also accepted by the ddeeccllaarree builtin. Individual array + elements may be assigned to using the _n_a_m_e[_s_u_b_s_c_r_i_p_t]=_v_a_l_u_e syntax in- + troduced above. When assigning to an indexed array, if _n_a_m_e is sub- + scripted by a negative number, that number is interpreted as relative + to one greater than the maximum index of _n_a_m_e, so negative indices count back from the end of the array, and an index of -1 references the last element. - The += operator will append to an array variable when assigning using + The += operator will append to an array variable when assigning using the compound assignment syntax; see PPAARRAAMMEETTEERRSS above. - Any element of an array may be referenced using ${_n_a_m_e[_s_u_b_s_c_r_i_p_t]}. + Any element of an array may be referenced using ${_n_a_m_e[_s_u_b_s_c_r_i_p_t]}. The braces are required to avoid conflicts with pathname expansion. If - _s_u_b_s_c_r_i_p_t is @@ or **, the word expands to all members of _n_a_m_e. These - subscripts differ only when the word appears within double quotes. If + _s_u_b_s_c_r_i_p_t is @@ or **, the word expands to all members of _n_a_m_e. These + subscripts differ only when the word appears within double quotes. If the word is double-quoted, ${_n_a_m_e[*]} expands to a single word with the - value of each array member separated by the first character of the IIFFSS + value of each array member separated by the first character of the IIFFSS special variable, and ${_n_a_m_e[@]} expands each element of _n_a_m_e to a sep- - arate word. When there are no array members, ${_n_a_m_e[@]} expands to - nothing. If the double-quoted expansion occurs within a word, the ex- + arate word. When there are no array members, ${_n_a_m_e[@]} expands to + nothing. If the double-quoted expansion occurs within a word, the ex- pansion of the first parameter is joined with the beginning part of the - original word, and the expansion of the last parameter is joined with + original word, and the expansion of the last parameter is joined with the last part of the original word. This is analogous to the expansion - of the special parameters ** and @@ (see SSppeecciiaall PPaarraammeetteerrss above). - ${#_n_a_m_e[_s_u_b_s_c_r_i_p_t]} expands to the length of ${_n_a_m_e[_s_u_b_s_c_r_i_p_t]}. If + of the special parameters ** and @@ (see SSppeecciiaall PPaarraammeetteerrss above). + ${#_n_a_m_e[_s_u_b_s_c_r_i_p_t]} expands to the length of ${_n_a_m_e[_s_u_b_s_c_r_i_p_t]}. If _s_u_b_s_c_r_i_p_t is ** or @@, the expansion is the number of elements in the ar- ray. If the _s_u_b_s_c_r_i_p_t used to reference an element of an indexed array - evaluates to a number less than zero, it is interpreted as relative to - one greater than the maximum index of the array, so negative indices + evaluates to a number less than zero, it is interpreted as relative to + one greater than the maximum index of the array, so negative indices count back from the end of the array, and an index of -1 references the last element. Referencing an array variable without a subscript is equivalent to ref- - erencing the array with a subscript of 0. Any reference to a variable + erencing the array with a subscript of 0. Any reference to a variable using a valid subscript is legal, and bbaasshh will create an array if nec- essary. - An array variable is considered set if a subscript has been assigned a + An array variable is considered set if a subscript has been assigned a value. The null string is a valid value. - It is possible to obtain the keys (indices) of an array as well as the - values. ${!!_n_a_m_e[_@]} and ${!!_n_a_m_e[_*]} expand to the indices assigned in + It is possible to obtain the keys (indices) of an array as well as the + values. ${!!_n_a_m_e[_@]} and ${!!_n_a_m_e[_*]} expand to the indices assigned in array variable _n_a_m_e. The treatment when in double quotes is similar to the expansion of the special parameters _@ and _* within double quotes. The uunnsseett builtin is used to destroy arrays. uunnsseett _n_a_m_e[_s_u_b_s_c_r_i_p_t] de- stroys the array element at index _s_u_b_s_c_r_i_p_t, for both indexed and asso- - ciative arrays. Negative subscripts to indexed arrays are interpreted - as described above. Unsetting the last element of an array variable - does not unset the variable. uunnsseett _n_a_m_e, where _n_a_m_e is an array, re- + ciative arrays. Negative subscripts to indexed arrays are interpreted + as described above. Unsetting the last element of an array variable + does not unset the variable. uunnsseett _n_a_m_e, where _n_a_m_e is an array, re- moves the entire array. uunnsseett _n_a_m_e[_s_u_b_s_c_r_i_p_t], where _s_u_b_s_c_r_i_p_t is ** or @@, behaves differently depending on whether _n_a_m_e is an indexed or asso- - ciative array. If _n_a_m_e is an associative array, this unsets the ele- + ciative array. If _n_a_m_e is an associative array, this unsets the ele- ment with subscript ** or @@. If _n_a_m_e is an indexed array, unset removes all of the elements but does not remove the array itself. - When using a variable name with a subscript as an argument to a com- - mand, such as with uunnsseett, without using the word expansion syntax de- + When using a variable name with a subscript as an argument to a com- + mand, such as with uunnsseett, without using the word expansion syntax de- scribed above, the argument is subject to pathname expansion. If path- name expansion is not desired, the argument should be quoted. - The ddeeccllaarree, llooccaall, and rreeaaddoonnllyy builtins each accept a --aa option to - specify an indexed array and a --AA option to specify an associative ar- - ray. If both options are supplied, --AA takes precedence. The rreeaadd - builtin accepts a --aa option to assign a list of words read from the + The ddeeccllaarree, llooccaall, and rreeaaddoonnllyy builtins each accept a --aa option to + specify an indexed array and a --AA option to specify an associative ar- + ray. If both options are supplied, --AA takes precedence. The rreeaadd + builtin accepts a --aa option to assign a list of words read from the standard input to an array. The sseett and ddeeccllaarree builtins display array values in a way that allows them to be reused as assignments. EEXXPPAANNSSIIOONN Expansion is performed on the command line after it has been split into - words. There are seven kinds of expansion performed: _b_r_a_c_e _e_x_p_a_n_s_i_o_n, - _t_i_l_d_e _e_x_p_a_n_s_i_o_n, _p_a_r_a_m_e_t_e_r _a_n_d _v_a_r_i_a_b_l_e _e_x_p_a_n_s_i_o_n, _c_o_m_m_a_n_d _s_u_b_s_t_i_t_u_- + words. There are seven kinds of expansion performed: _b_r_a_c_e _e_x_p_a_n_s_i_o_n, + _t_i_l_d_e _e_x_p_a_n_s_i_o_n, _p_a_r_a_m_e_t_e_r _a_n_d _v_a_r_i_a_b_l_e _e_x_p_a_n_s_i_o_n, _c_o_m_m_a_n_d _s_u_b_s_t_i_t_u_- _t_i_o_n, _a_r_i_t_h_m_e_t_i_c _e_x_p_a_n_s_i_o_n, _w_o_r_d _s_p_l_i_t_t_i_n_g, and _p_a_t_h_n_a_m_e _e_x_p_a_n_s_i_o_n. The order of expansions is: brace expansion; tilde expansion, parameter - and variable expansion, arithmetic expansion, and command substitution - (done in a left-to-right fashion); word splitting; and pathname expan- + and variable expansion, arithmetic expansion, and command substitution + (done in a left-to-right fashion); word splitting; and pathname expan- sion. On systems that can support it, there is an additional expansion avail- - able: _p_r_o_c_e_s_s _s_u_b_s_t_i_t_u_t_i_o_n. This is performed at the same time as - tilde, parameter, variable, and arithmetic expansion and command sub- + able: _p_r_o_c_e_s_s _s_u_b_s_t_i_t_u_t_i_o_n. This is performed at the same time as + tilde, parameter, variable, and arithmetic expansion and command sub- stitution. - After these expansions are performed, quote characters present in the - original word are removed unless they have been quoted themselves + After these expansions are performed, quote characters present in the + original word are removed unless they have been quoted themselves (_q_u_o_t_e _r_e_m_o_v_a_l). - Only brace expansion, word splitting, and pathname expansion can in- - crease the number of words of the expansion; other expansions expand a - single word to a single word. The only exceptions to this are the ex- + Only brace expansion, word splitting, and pathname expansion can in- + crease the number of words of the expansion; other expansions expand a + single word to a single word. The only exceptions to this are the ex- pansions of "$$@@" and "$${{_n_a_m_e[[@@]]}}", and, in most cases, $$** and $${{_n_a_m_e[[**]]}} as explained above (see PPAARRAAMMEETTEERRSS). BBrraaccee EExxppaannssiioonn _B_r_a_c_e _e_x_p_a_n_s_i_o_n is a mechanism by which arbitrary strings may be gener- - ated. This mechanism is similar to _p_a_t_h_n_a_m_e _e_x_p_a_n_s_i_o_n, but the file- + ated. This mechanism is similar to _p_a_t_h_n_a_m_e _e_x_p_a_n_s_i_o_n, but the file- names generated need not exist. Patterns to be brace expanded take the form of an optional _p_r_e_a_m_b_l_e, followed by either a series of comma-sep- - arated strings or a sequence expression between a pair of braces, fol- - lowed by an optional _p_o_s_t_s_c_r_i_p_t. The preamble is prefixed to each + arated strings or a sequence expression between a pair of braces, fol- + lowed by an optional _p_o_s_t_s_c_r_i_p_t. The preamble is prefixed to each string contained within the braces, and the postscript is then appended to each resulting string, expanding left to right. - Brace expansions may be nested. The results of each expanded string - are not sorted; left to right order is preserved. For example, + Brace expansions may be nested. The results of each expanded string + are not sorted; left to right order is preserved. For example, a{{d,c,b}}e expands into `ade ace abe'. - A sequence expression takes the form {{_x...._y[[...._i_n_c_r]]}}, where _x and _y are - either integers or single letters, and _i_n_c_r, an optional increment, is + A sequence expression takes the form {{_x...._y[[...._i_n_c_r]]}}, where _x and _y are + either integers or single letters, and _i_n_c_r, an optional increment, is an integer. When integers are supplied, the expression expands to each - number between _x and _y, inclusive. Supplied integers may be prefixed - with _0 to force each term to have the same width. When either _x or _y - begins with a zero, the shell attempts to force all generated terms to - contain the same number of digits, zero-padding where necessary. When - letters are supplied, the expression expands to each character lexico- - graphically between _x and _y, inclusive, using the default C locale. - Note that both _x and _y must be of the same type (integer or letter). - When the increment is supplied, it is used as the difference between + number between _x and _y, inclusive. Supplied integers may be prefixed + with _0 to force each term to have the same width. When either _x or _y + begins with a zero, the shell attempts to force all generated terms to + contain the same number of digits, zero-padding where necessary. When + letters are supplied, the expression expands to each character lexico- + graphically between _x and _y, inclusive, using the default C locale. + Note that both _x and _y must be of the same type (integer or letter). + When the increment is supplied, it is used as the difference between each term. The default increment is 1 or -1 as appropriate. Brace expansion is performed before any other expansions, and any char- - acters special to other expansions are preserved in the result. It is - strictly textual. BBaasshh does not apply any syntactic interpretation to + acters special to other expansions are preserved in the result. It is + strictly textual. BBaasshh does not apply any syntactic interpretation to the context of the expansion or the text between the braces. - A correctly-formed brace expansion must contain unquoted opening and + A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence ex- pression. Any incorrectly formed brace expansion is left unchanged. A - {{ or ,, may be quoted with a backslash to prevent its being considered - part of a brace expression. To avoid conflicts with parameter expan- + {{ or ,, may be quoted with a backslash to prevent its being considered + part of a brace expression. To avoid conflicts with parameter expan- sion, the string $${{ is not considered eligible for brace expansion, and inhibits brace expansion until the closing }}. @@ -1632,36 +1649,36 @@ EEXXPPAANNSSIIOONN or chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} - Brace expansion introduces a slight incompatibility with historical - versions of sshh. sshh does not treat opening or closing braces specially - when they appear as part of a word, and preserves them in the output. - BBaasshh removes braces from words as a consequence of brace expansion. - For example, a word entered to sshh as _f_i_l_e_{_1_,_2_} appears identically in - the output. The same word is output as _f_i_l_e_1 _f_i_l_e_2 after expansion by - bbaasshh. If strict compatibility with sshh is desired, start bbaasshh with the + Brace expansion introduces a slight incompatibility with historical + versions of sshh. sshh does not treat opening or closing braces specially + when they appear as part of a word, and preserves them in the output. + BBaasshh removes braces from words as a consequence of brace expansion. + For example, a word entered to sshh as _f_i_l_e_{_1_,_2_} appears identically in + the output. The same word is output as _f_i_l_e_1 _f_i_l_e_2 after expansion by + bbaasshh. If strict compatibility with sshh is desired, start bbaasshh with the ++BB option or disable brace expansion with the ++BB option to the sseett com- mand (see SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS below). TTiillddee EExxppaannssiioonn - If a word begins with an unquoted tilde character (`~~'), all of the - characters preceding the first unquoted slash (or all characters, if - there is no unquoted slash) are considered a _t_i_l_d_e_-_p_r_e_f_i_x. If none of - the characters in the tilde-prefix are quoted, the characters in the - tilde-prefix following the tilde are treated as a possible _l_o_g_i_n _n_a_m_e. - If this login name is the null string, the tilde is replaced with the - value of the shell parameter HHOOMMEE. If HHOOMMEE is unset, the home direc- - tory of the user executing the shell is substituted instead. Other- - wise, the tilde-prefix is replaced with the home directory associated + If a word begins with an unquoted tilde character (`~~'), all of the + characters preceding the first unquoted slash (or all characters, if + there is no unquoted slash) are considered a _t_i_l_d_e_-_p_r_e_f_i_x. If none of + the characters in the tilde-prefix are quoted, the characters in the + tilde-prefix following the tilde are treated as a possible _l_o_g_i_n _n_a_m_e. + If this login name is the null string, the tilde is replaced with the + value of the shell parameter HHOOMMEE. If HHOOMMEE is unset, the home direc- + tory of the user executing the shell is substituted instead. Other- + wise, the tilde-prefix is replaced with the home directory associated with the specified login name. - If the tilde-prefix is a `~+', the value of the shell variable PPWWDD re- - places the tilde-prefix. If the tilde-prefix is a `~-', the value of - the shell variable OOLLDDPPWWDD, if it is set, is substituted. If the char- - acters following the tilde in the tilde-prefix consist of a number _N, - optionally prefixed by a `+' or a `-', the tilde-prefix is replaced + If the tilde-prefix is a `~+', the value of the shell variable PPWWDD re- + places the tilde-prefix. If the tilde-prefix is a `~-', the value of + the shell variable OOLLDDPPWWDD, if it is set, is substituted. If the char- + acters following the tilde in the tilde-prefix consist of a number _N, + optionally prefixed by a `+' or a `-', the tilde-prefix is replaced with the corresponding element from the directory stack, as it would be displayed by the ddiirrss builtin invoked with the tilde-prefix as an argu- - ment. If the characters following the tilde in the tilde-prefix con- + ment. If the characters following the tilde in the tilde-prefix con- sist of a number without a leading `+' or `-', `+' is assumed. If the login name is invalid, or the tilde expansion fails, the word is @@ -1670,140 +1687,140 @@ EEXXPPAANNSSIIOONN Each variable assignment is checked for unquoted tilde-prefixes immedi- ately following a :: or the first ==. In these cases, tilde expansion is also performed. Consequently, one may use filenames with tildes in as- - signments to PPAATTHH, MMAAIILLPPAATTHH, and CCDDPPAATTHH, and the shell assigns the ex- + signments to PPAATTHH, MMAAIILLPPAATTHH, and CCDDPPAATTHH, and the shell assigns the ex- panded value. - Bash also performs tilde expansion on words satisfying the conditions + Bash also performs tilde expansion on words satisfying the conditions of variable assignments (as described above under PPAARRAAMMEETTEERRSS) when they - appear as arguments to simple commands. Bash does not do this, except + appear as arguments to simple commands. Bash does not do this, except for the _d_e_c_l_a_r_a_t_i_o_n commands listed above, when in _p_o_s_i_x _m_o_d_e. PPaarraammeetteerr EExxppaannssiioonn The `$$' character introduces parameter expansion, command substitution, - or arithmetic expansion. The parameter name or symbol to be expanded - may be enclosed in braces, which are optional but serve to protect the - variable to be expanded from characters immediately following it which + or arithmetic expansion. The parameter name or symbol to be expanded + may be enclosed in braces, which are optional but serve to protect the + variable to be expanded from characters immediately following it which could be interpreted as part of the name. - When braces are used, the matching ending brace is the first `}}' not + When braces are used, the matching ending brace is the first `}}' not escaped by a backslash or within a quoted string, and not within an em- - bedded arithmetic expansion, command substitution, or parameter expan- + bedded arithmetic expansion, command substitution, or parameter expan- sion. ${_p_a_r_a_m_e_t_e_r} - The value of _p_a_r_a_m_e_t_e_r is substituted. The braces are required - when _p_a_r_a_m_e_t_e_r is a positional parameter with more than one + The value of _p_a_r_a_m_e_t_e_r is substituted. The braces are required + when _p_a_r_a_m_e_t_e_r is a positional parameter with more than one digit, or when _p_a_r_a_m_e_t_e_r is followed by a character which is not to be interpreted as part of its name. The _p_a_r_a_m_e_t_e_r is a shell - parameter as described above PPAARRAAMMEETTEERRSS) or an array reference + parameter as described above PPAARRAAMMEETTEERRSS) or an array reference (AArrrraayyss). - If the first character of _p_a_r_a_m_e_t_e_r is an exclamation point (!!), and + If the first character of _p_a_r_a_m_e_t_e_r is an exclamation point (!!), and _p_a_r_a_m_e_t_e_r is not a _n_a_m_e_r_e_f, it introduces a level of indirection. BBaasshh uses the value formed by expanding the rest of _p_a_r_a_m_e_t_e_r as the new _p_a_- - _r_a_m_e_t_e_r; this is then expanded and that value is used in the rest of - the expansion, rather than the expansion of the original _p_a_r_a_m_e_t_e_r. + _r_a_m_e_t_e_r; this is then expanded and that value is used in the rest of + the expansion, rather than the expansion of the original _p_a_r_a_m_e_t_e_r. This is known as _i_n_d_i_r_e_c_t _e_x_p_a_n_s_i_o_n. The value is subject to tilde ex- - pansion, parameter expansion, command substitution, and arithmetic ex- - pansion. If _p_a_r_a_m_e_t_e_r is a nameref, this expands to the name of the - parameter referenced by _p_a_r_a_m_e_t_e_r instead of performing the complete - indirect expansion. The exceptions to this are the expansions of - ${!!_p_r_e_f_i_x**} and ${!!_n_a_m_e[_@]} described below. The exclamation point - must immediately follow the left brace in order to introduce indirec- + pansion, parameter expansion, command substitution, and arithmetic ex- + pansion. If _p_a_r_a_m_e_t_e_r is a nameref, this expands to the name of the + parameter referenced by _p_a_r_a_m_e_t_e_r instead of performing the complete + indirect expansion. The exceptions to this are the expansions of + ${!!_p_r_e_f_i_x**} and ${!!_n_a_m_e[_@]} described below. The exclamation point + must immediately follow the left brace in order to introduce indirec- tion. In each of the cases below, _w_o_r_d is subject to tilde expansion, parame- ter expansion, command substitution, and arithmetic expansion. When not performing substring expansion, using the forms documented be- - low (e.g., ::--), bbaasshh tests for a parameter that is unset or null. - Omitting the colon results in a test only for a parameter that is un- + low (e.g., ::--), bbaasshh tests for a parameter that is unset or null. + Omitting the colon results in a test only for a parameter that is un- set. ${_p_a_r_a_m_e_t_e_r::--_w_o_r_d} - UUssee DDeeffaauulltt VVaalluueess. If _p_a_r_a_m_e_t_e_r is unset or null, the expan- - sion of _w_o_r_d is substituted. Otherwise, the value of _p_a_r_a_m_e_t_e_r + UUssee DDeeffaauulltt VVaalluueess. If _p_a_r_a_m_e_t_e_r is unset or null, the expan- + sion of _w_o_r_d is substituted. Otherwise, the value of _p_a_r_a_m_e_t_e_r is substituted. ${_p_a_r_a_m_e_t_e_r::==_w_o_r_d} - AAssssiiggnn DDeeffaauulltt VVaalluueess. If _p_a_r_a_m_e_t_e_r is unset or null, the ex- - pansion of _w_o_r_d is assigned to _p_a_r_a_m_e_t_e_r. The value of _p_a_r_a_m_e_- - _t_e_r is then substituted. Positional parameters and special pa- + AAssssiiggnn DDeeffaauulltt VVaalluueess. If _p_a_r_a_m_e_t_e_r is unset or null, the ex- + pansion of _w_o_r_d is assigned to _p_a_r_a_m_e_t_e_r. The value of _p_a_r_a_m_e_- + _t_e_r is then substituted. Positional parameters and special pa- rameters may not be assigned to in this way. ${_p_a_r_a_m_e_t_e_r::??_w_o_r_d} - DDiissppllaayy EErrrroorr iiff NNuullll oorr UUnnsseett. If _p_a_r_a_m_e_t_e_r is null or unset, - the expansion of _w_o_r_d (or a message to that effect if _w_o_r_d is - not present) is written to the standard error and the shell, if + DDiissppllaayy EErrrroorr iiff NNuullll oorr UUnnsseett. If _p_a_r_a_m_e_t_e_r is null or unset, + the expansion of _w_o_r_d (or a message to that effect if _w_o_r_d is + not present) is written to the standard error and the shell, if it is not interactive, exits. Otherwise, the value of _p_a_r_a_m_e_t_e_r is substituted. ${_p_a_r_a_m_e_t_e_r::++_w_o_r_d} - UUssee AAlltteerrnnaattee VVaalluuee. If _p_a_r_a_m_e_t_e_r is null or unset, nothing is + UUssee AAlltteerrnnaattee VVaalluuee. If _p_a_r_a_m_e_t_e_r is null or unset, nothing is substituted, otherwise the expansion of _w_o_r_d is substituted. ${_p_a_r_a_m_e_t_e_r::_o_f_f_s_e_t} ${_p_a_r_a_m_e_t_e_r::_o_f_f_s_e_t::_l_e_n_g_t_h} - SSuubbssttrriinngg EExxppaannssiioonn. Expands to up to _l_e_n_g_t_h characters of the - value of _p_a_r_a_m_e_t_e_r starting at the character specified by _o_f_f_- - _s_e_t. If _p_a_r_a_m_e_t_e_r is @@ or **, an indexed array subscripted by @@ - or **, or an associative array name, the results differ as de- - scribed below. If _l_e_n_g_t_h is omitted, expands to the substring + SSuubbssttrriinngg EExxppaannssiioonn. Expands to up to _l_e_n_g_t_h characters of the + value of _p_a_r_a_m_e_t_e_r starting at the character specified by _o_f_f_- + _s_e_t. If _p_a_r_a_m_e_t_e_r is @@ or **, an indexed array subscripted by @@ + or **, or an associative array name, the results differ as de- + scribed below. If _l_e_n_g_t_h is omitted, expands to the substring of the value of _p_a_r_a_m_e_t_e_r starting at the character specified by _o_f_f_s_e_t and extending to the end of the value. _l_e_n_g_t_h and _o_f_f_s_e_t are arithmetic expressions (see AARRIITTHHMMEETTIICC EEVVAALLUUAATTIIOONN below). - If _o_f_f_s_e_t evaluates to a number less than zero, the value is + If _o_f_f_s_e_t evaluates to a number less than zero, the value is used as an offset in characters from the end of the value of _p_a_- - _r_a_m_e_t_e_r. If _l_e_n_g_t_h evaluates to a number less than zero, it is + _r_a_m_e_t_e_r. If _l_e_n_g_t_h evaluates to a number less than zero, it is interpreted as an offset in characters from the end of the value - of _p_a_r_a_m_e_t_e_r rather than a number of characters, and the expan- - sion is the characters between _o_f_f_s_e_t and that result. Note - that a negative offset must be separated from the colon by at + of _p_a_r_a_m_e_t_e_r rather than a number of characters, and the expan- + sion is the characters between _o_f_f_s_e_t and that result. Note + that a negative offset must be separated from the colon by at least one space to avoid being confused with the ::-- expansion. - If _p_a_r_a_m_e_t_e_r is @@ or **, the result is _l_e_n_g_t_h positional parame- - ters beginning at _o_f_f_s_e_t. A negative _o_f_f_s_e_t is taken relative - to one greater than the greatest positional parameter, so an + If _p_a_r_a_m_e_t_e_r is @@ or **, the result is _l_e_n_g_t_h positional parame- + ters beginning at _o_f_f_s_e_t. A negative _o_f_f_s_e_t is taken relative + to one greater than the greatest positional parameter, so an offset of -1 evaluates to the last positional parameter (or 0 if - there are no positional parameters). It is an expansion error + there are no positional parameters). It is an expansion error if _l_e_n_g_t_h evaluates to a number less than zero. If _p_a_r_a_m_e_t_e_r is an indexed array name subscripted by @ or *, the - result is the _l_e_n_g_t_h members of the array beginning with ${_p_a_- - _r_a_m_e_t_e_r[_o_f_f_s_e_t]}. A negative _o_f_f_s_e_t is taken relative to one + result is the _l_e_n_g_t_h members of the array beginning with ${_p_a_- + _r_a_m_e_t_e_r[_o_f_f_s_e_t]}. A negative _o_f_f_s_e_t is taken relative to one greater than the maximum index of the specified array. It is an expansion error if _l_e_n_g_t_h evaluates to a number less than zero. Substring expansion applied to an associative array produces un- defined results. - Substring indexing is zero-based unless the positional parame- - ters are used, in which case the indexing starts at 1 by de- - fault. If _o_f_f_s_e_t is 0, and the positional parameters are used, + Substring indexing is zero-based unless the positional parame- + ters are used, in which case the indexing starts at 1 by de- + fault. If _o_f_f_s_e_t is 0, and the positional parameters are used, $$00 is prefixed to the list. ${!!_p_r_e_f_i_x**} ${!!_p_r_e_f_i_x@@} - NNaammeess mmaattcchhiinngg pprreeffiixx. Expands to the names of variables whose + NNaammeess mmaattcchhiinngg pprreeffiixx. Expands to the names of variables whose names begin with _p_r_e_f_i_x, separated by the first character of the - IIFFSS special variable. When _@ is used and the expansion appears - within double quotes, each variable name expands to a separate + IIFFSS special variable. When _@ is used and the expansion appears + within double quotes, each variable name expands to a separate word. ${!!_n_a_m_e[_@]} ${!!_n_a_m_e[_*]} - LLiisstt ooff aarrrraayy kkeeyyss. If _n_a_m_e is an array variable, expands to - the list of array indices (keys) assigned in _n_a_m_e. If _n_a_m_e is - not an array, expands to 0 if _n_a_m_e is set and null otherwise. - When _@ is used and the expansion appears within double quotes, + LLiisstt ooff aarrrraayy kkeeyyss. If _n_a_m_e is an array variable, expands to + the list of array indices (keys) assigned in _n_a_m_e. If _n_a_m_e is + not an array, expands to 0 if _n_a_m_e is set and null otherwise. + When _@ is used and the expansion appears within double quotes, each key expands to a separate word. ${##_p_a_r_a_m_e_t_e_r} - PPaarraammeetteerr lleennggtthh. The length in characters of the value of _p_a_- - _r_a_m_e_t_e_r is substituted. If _p_a_r_a_m_e_t_e_r is ** or @@, the value sub- - stituted is the number of positional parameters. If _p_a_r_a_m_e_t_e_r + PPaarraammeetteerr lleennggtthh. The length in characters of the value of _p_a_- + _r_a_m_e_t_e_r is substituted. If _p_a_r_a_m_e_t_e_r is ** or @@, the value sub- + stituted is the number of positional parameters. If _p_a_r_a_m_e_t_e_r is an array name subscripted by ** or @@, the value substituted is the number of elements in the array. If _p_a_r_a_m_e_t_e_r is an indexed - array name subscripted by a negative number, that number is in- - terpreted as relative to one greater than the maximum index of - _p_a_r_a_m_e_t_e_r, so negative indices count back from the end of the + array name subscripted by a negative number, that number is in- + terpreted as relative to one greater than the maximum index of + _p_a_r_a_m_e_t_e_r, so negative indices count back from the end of the array, and an index of -1 references the last element. ${_p_a_r_a_m_e_t_e_r##_w_o_r_d} @@ -1811,15 +1828,15 @@ EEXXPPAANNSSIIOONN RReemmoovvee mmaattcchhiinngg pprreeffiixx ppaatttteerrnn. The _w_o_r_d is expanded to produce a pattern just as in pathname expansion, and matched against the expanded value of _p_a_r_a_m_e_t_e_r using the rules described under PPaatt-- - tteerrnn MMaattcchhiinngg below. If the pattern matches the beginning of - the value of _p_a_r_a_m_e_t_e_r, then the result of the expansion is the - expanded value of _p_a_r_a_m_e_t_e_r with the shortest matching pattern - (the ``##'' case) or the longest matching pattern (the ``####'' - case) deleted. If _p_a_r_a_m_e_t_e_r is @@ or **, the pattern removal op- + tteerrnn MMaattcchhiinngg below. If the pattern matches the beginning of + the value of _p_a_r_a_m_e_t_e_r, then the result of the expansion is the + expanded value of _p_a_r_a_m_e_t_e_r with the shortest matching pattern + (the ``##'' case) or the longest matching pattern (the ``####'' + case) deleted. If _p_a_r_a_m_e_t_e_r is @@ or **, the pattern removal op- eration is applied to each positional parameter in turn, and the expansion is the resultant list. If _p_a_r_a_m_e_t_e_r is an array vari- - able subscripted with @@ or **, the pattern removal operation is - applied to each member of the array in turn, and the expansion + able subscripted with @@ or **, the pattern removal operation is + applied to each member of the array in turn, and the expansion is the resultant list. ${_p_a_r_a_m_e_t_e_r%%_w_o_r_d} @@ -1827,15 +1844,15 @@ EEXXPPAANNSSIIOONN RReemmoovvee mmaattcchhiinngg ssuuffffiixx ppaatttteerrnn. The _w_o_r_d is expanded to produce a pattern just as in pathname expansion, and matched against the expanded value of _p_a_r_a_m_e_t_e_r using the rules described under PPaatt-- - tteerrnn MMaattcchhiinngg below. If the pattern matches a trailing portion - of the expanded value of _p_a_r_a_m_e_t_e_r, then the result of the ex- - pansion is the expanded value of _p_a_r_a_m_e_t_e_r with the shortest - matching pattern (the ``%%'' case) or the longest matching pat- - tern (the ``%%%%'' case) deleted. If _p_a_r_a_m_e_t_e_r is @@ or **, the - pattern removal operation is applied to each positional parame- + tteerrnn MMaattcchhiinngg below. If the pattern matches a trailing portion + of the expanded value of _p_a_r_a_m_e_t_e_r, then the result of the ex- + pansion is the expanded value of _p_a_r_a_m_e_t_e_r with the shortest + matching pattern (the ``%%'' case) or the longest matching pat- + tern (the ``%%%%'' case) deleted. If _p_a_r_a_m_e_t_e_r is @@ or **, the + pattern removal operation is applied to each positional parame- ter in turn, and the expansion is the resultant list. If _p_a_r_a_m_- - _e_t_e_r is an array variable subscripted with @@ or **, the pattern - removal operation is applied to each member of the array in + _e_t_e_r is an array variable subscripted with @@ or **, the pattern + removal operation is applied to each member of the array in turn, and the expansion is the resultant list. ${_p_a_r_a_m_e_t_e_r//_p_a_t_t_e_r_n//_s_t_r_i_n_g} @@ -1843,116 +1860,116 @@ EEXXPPAANNSSIIOONN ${_p_a_r_a_m_e_t_e_r//##_p_a_t_t_e_r_n//_s_t_r_i_n_g} ${_p_a_r_a_m_e_t_e_r//%%_p_a_t_t_e_r_n//_s_t_r_i_n_g} PPaatttteerrnn ssuubbssttiittuuttiioonn. The _p_a_t_t_e_r_n is expanded to produce a pat- - tern just as in pathname expansion. _P_a_r_a_m_e_t_e_r is expanded and - the longest match of _p_a_t_t_e_r_n against its value is replaced with - _s_t_r_i_n_g. _s_t_r_i_n_g undergoes tilde expansion, parameter and vari- - able expansion, arithmetic expansion, command and process sub- - stitution, and quote removal. The match is performed using the + tern just as in pathname expansion. _P_a_r_a_m_e_t_e_r is expanded and + the longest match of _p_a_t_t_e_r_n against its value is replaced with + _s_t_r_i_n_g. _s_t_r_i_n_g undergoes tilde expansion, parameter and vari- + able expansion, arithmetic expansion, command and process sub- + stitution, and quote removal. The match is performed using the rules described under PPaatttteerrnn MMaattcchhiinngg below. In the first form - above, only the first match is replaced. If there are two + above, only the first match is replaced. If there are two slashes separating _p_a_r_a_m_e_t_e_r and _p_a_t_t_e_r_n (the second form - above), all matches of _p_a_t_t_e_r_n are replaced with _s_t_r_i_n_g. If - _p_a_t_t_e_r_n is preceded by ## (the third form above), it must match + above), all matches of _p_a_t_t_e_r_n are replaced with _s_t_r_i_n_g. If + _p_a_t_t_e_r_n is preceded by ## (the third form above), it must match at the beginning of the expanded value of _p_a_r_a_m_e_t_e_r. If _p_a_t_t_e_r_n - is preceded by %% (the fourth form above), it must match at the - end of the expanded value of _p_a_r_a_m_e_t_e_r. If the expansion of - _s_t_r_i_n_g is null, matches of _p_a_t_t_e_r_n are deleted. If _s_t_r_i_n_g is + is preceded by %% (the fourth form above), it must match at the + end of the expanded value of _p_a_r_a_m_e_t_e_r. If the expansion of + _s_t_r_i_n_g is null, matches of _p_a_t_t_e_r_n are deleted. If _s_t_r_i_n_g is null, matches of _p_a_t_t_e_r_n are deleted and the // following _p_a_t_t_e_r_n may be omitted. - If the ppaattssuubb__rreeppllaacceemmeenntt shell option is enabled using sshhoopptt, - any unquoted instances of && in _s_t_r_i_n_g are replaced with the + If the ppaattssuubb__rreeppllaacceemmeenntt shell option is enabled using sshhoopptt, + any unquoted instances of && in _s_t_r_i_n_g are replaced with the matching portion of _p_a_t_t_e_r_n. Quoting any part of _s_t_r_i_n_g inhibits replacement in the expansion - of the quoted portion, including replacement strings stored in - shell variables. Backslash will escape && in _s_t_r_i_n_g; the back- - slash is removed in order to permit a literal && in the replace- - ment string. Backslash can also be used to escape a backslash; - \\\\ results in a literal backslash in the replacement. Users - should take care if _s_t_r_i_n_g is double-quoted to avoid unwanted - interactions between the backslash and double-quoting, since - backslash has special meaning within double quotes. Pattern - substitution performs the check for unquoted && after expanding + of the quoted portion, including replacement strings stored in + shell variables. Backslash will escape && in _s_t_r_i_n_g; the back- + slash is removed in order to permit a literal && in the replace- + ment string. Backslash can also be used to escape a backslash; + \\\\ results in a literal backslash in the replacement. Users + should take care if _s_t_r_i_n_g is double-quoted to avoid unwanted + interactions between the backslash and double-quoting, since + backslash has special meaning within double quotes. Pattern + substitution performs the check for unquoted && after expanding _s_t_r_i_n_g; shell programmers should quote any occurrences of && they want to be taken literally in the replacement and ensure any in- stances of && they want to be replaced are unquoted. - If the nnooccaasseemmaattcchh shell option is enabled, the match is per- - formed without regard to the case of alphabetic characters. If - _p_a_r_a_m_e_t_e_r is @@ or **, the substitution operation is applied to - each positional parameter in turn, and the expansion is the re- - sultant list. If _p_a_r_a_m_e_t_e_r is an array variable subscripted - with @@ or **, the substitution operation is applied to each mem- - ber of the array in turn, and the expansion is the resultant + If the nnooccaasseemmaattcchh shell option is enabled, the match is per- + formed without regard to the case of alphabetic characters. If + _p_a_r_a_m_e_t_e_r is @@ or **, the substitution operation is applied to + each positional parameter in turn, and the expansion is the re- + sultant list. If _p_a_r_a_m_e_t_e_r is an array variable subscripted + with @@ or **, the substitution operation is applied to each mem- + ber of the array in turn, and the expansion is the resultant list. ${_p_a_r_a_m_e_t_e_r^^_p_a_t_t_e_r_n} ${_p_a_r_a_m_e_t_e_r^^^^_p_a_t_t_e_r_n} ${_p_a_r_a_m_e_t_e_r,,_p_a_t_t_e_r_n} ${_p_a_r_a_m_e_t_e_r,,,,_p_a_t_t_e_r_n} - CCaassee mmooddiiffiiccaattiioonn. This expansion modifies the case of alpha- - betic characters in _p_a_r_a_m_e_t_e_r. The _p_a_t_t_e_r_n is expanded to pro- + CCaassee mmooddiiffiiccaattiioonn. This expansion modifies the case of alpha- + betic characters in _p_a_r_a_m_e_t_e_r. The _p_a_t_t_e_r_n is expanded to pro- duce a pattern just as in pathname expansion. Each character in - the expanded value of _p_a_r_a_m_e_t_e_r is tested against _p_a_t_t_e_r_n, and, - if it matches the pattern, its case is converted. The pattern - should not attempt to match more than one character. The ^^ op- + the expanded value of _p_a_r_a_m_e_t_e_r is tested against _p_a_t_t_e_r_n, and, + if it matches the pattern, its case is converted. The pattern + should not attempt to match more than one character. The ^^ op- erator converts lowercase letters matching _p_a_t_t_e_r_n to uppercase; the ,, operator converts matching uppercase letters to lowercase. - The ^^^^ and ,,,, expansions convert each matched character in the - expanded value; the ^^ and ,, expansions match and convert only - the first character in the expanded value. If _p_a_t_t_e_r_n is omit- - ted, it is treated like a ??, which matches every character. If - _p_a_r_a_m_e_t_e_r is @@ or **, the case modification operation is applied - to each positional parameter in turn, and the expansion is the - resultant list. If _p_a_r_a_m_e_t_e_r is an array variable subscripted - with @@ or **, the case modification operation is applied to each - member of the array in turn, and the expansion is the resultant + The ^^^^ and ,,,, expansions convert each matched character in the + expanded value; the ^^ and ,, expansions match and convert only + the first character in the expanded value. If _p_a_t_t_e_r_n is omit- + ted, it is treated like a ??, which matches every character. If + _p_a_r_a_m_e_t_e_r is @@ or **, the case modification operation is applied + to each positional parameter in turn, and the expansion is the + resultant list. If _p_a_r_a_m_e_t_e_r is an array variable subscripted + with @@ or **, the case modification operation is applied to each + member of the array in turn, and the expansion is the resultant list. ${_p_a_r_a_m_e_t_e_r@@_o_p_e_r_a_t_o_r} PPaarraammeetteerr ttrraannssffoorrmmaattiioonn. The expansion is either a transforma- - tion of the value of _p_a_r_a_m_e_t_e_r or information about _p_a_r_a_m_e_t_e_r - itself, depending on the value of _o_p_e_r_a_t_o_r. Each _o_p_e_r_a_t_o_r is a + tion of the value of _p_a_r_a_m_e_t_e_r or information about _p_a_r_a_m_e_t_e_r + itself, depending on the value of _o_p_e_r_a_t_o_r. Each _o_p_e_r_a_t_o_r is a single letter: - UU The expansion is a string that is the value of _p_a_r_a_m_e_t_e_r - with lowercase alphabetic characters converted to upper- + UU The expansion is a string that is the value of _p_a_r_a_m_e_t_e_r + with lowercase alphabetic characters converted to upper- case. - uu The expansion is a string that is the value of _p_a_r_a_m_e_t_e_r + uu The expansion is a string that is the value of _p_a_r_a_m_e_t_e_r with the first character converted to uppercase, if it is alphabetic. - LL The expansion is a string that is the value of _p_a_r_a_m_e_t_e_r - with uppercase alphabetic characters converted to lower- + LL The expansion is a string that is the value of _p_a_r_a_m_e_t_e_r + with uppercase alphabetic characters converted to lower- case. - QQ The expansion is a string that is the value of _p_a_r_a_m_e_t_e_r + QQ The expansion is a string that is the value of _p_a_r_a_m_e_t_e_r quoted in a format that can be reused as input. - EE The expansion is a string that is the value of _p_a_r_a_m_e_t_e_r - with backslash escape sequences expanded as with the + EE The expansion is a string that is the value of _p_a_r_a_m_e_t_e_r + with backslash escape sequences expanded as with the $$''......'' quoting mechanism. PP The expansion is a string that is the result of expanding the value of _p_a_r_a_m_e_t_e_r as if it were a prompt string (see PPRROOMMPPTTIINNGG below). - AA The expansion is a string in the form of an assignment - statement or ddeeccllaarree command that, if evaluated, will + AA The expansion is a string in the form of an assignment + statement or ddeeccllaarree command that, if evaluated, will recreate _p_a_r_a_m_e_t_e_r with its attributes and value. KK Produces a possibly-quoted version of the value of _p_a_r_a_m_- _e_t_e_r, except that it prints the values of indexed and as- - sociative arrays as a sequence of quoted key-value pairs + sociative arrays as a sequence of quoted key-value pairs (see AArrrraayyss above). - aa The expansion is a string consisting of flag values rep- + aa The expansion is a string consisting of flag values rep- resenting _p_a_r_a_m_e_t_e_r's attributes. - kk Like the K transformation, but expands the keys and val- - ues of indexed and associative arrays to separate words + kk Like the K transformation, but expands the keys and val- + ues of indexed and associative arrays to separate words after word splitting. - If _p_a_r_a_m_e_t_e_r is @@ or **, the operation is applied to each posi- - tional parameter in turn, and the expansion is the resultant - list. If _p_a_r_a_m_e_t_e_r is an array variable subscripted with @@ or + If _p_a_r_a_m_e_t_e_r is @@ or **, the operation is applied to each posi- + tional parameter in turn, and the expansion is the resultant + list. If _p_a_r_a_m_e_t_e_r is an array variable subscripted with @@ or **, the operation is applied to each member of the array in turn, and the expansion is the resultant list. - The result of the expansion is subject to word splitting and + The result of the expansion is subject to word splitting and pathname expansion as described below. CCoommmmaanndd SSuubbssttiittuuttiioonn @@ -1966,132 +1983,135 @@ EEXXPPAANNSSIIOONN BBaasshh performs the expansion by executing _c_o_m_m_a_n_d in a subshell environ- ment and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are - not deleted, but they may be removed during word splitting. The com- - mand substitution $$((ccaatt _f_i_l_e)) can be replaced by the equivalent but + not deleted, but they may be removed during word splitting. The com- + mand substitution $$((ccaatt _f_i_l_e)) can be replaced by the equivalent but faster $$((<< _f_i_l_e)). - When the old-style backquote form of substitution is used, backslash - retains its literal meaning except when followed by $$, ``, or \\. The + When the old-style backquote form of substitution is used, backslash + retains its literal meaning except when followed by $$, ``, or \\. The first backquote not preceded by a backslash terminates the command sub- - stitution. When using the $(_c_o_m_m_a_n_d) form, all characters between the + stitution. When using the $(_c_o_m_m_a_n_d) form, all characters between the parentheses make up the command; none are treated specially. Command substitutions may be nested. To nest when using the backquoted form, escape the inner backquotes with backslashes. - If the substitution appears within double quotes, word splitting and + If the substitution appears within double quotes, word splitting and pathname expansion are not performed on the results. AArriitthhmmeettiicc EExxppaannssiioonn - Arithmetic expansion allows the evaluation of an arithmetic expression - and the substitution of the result. The format for arithmetic expan- + Arithmetic expansion allows the evaluation of an arithmetic expression + and the substitution of the result. The format for arithmetic expan- sion is: $$((((_e_x_p_r_e_s_s_i_o_n)))) - The _e_x_p_r_e_s_s_i_o_n undergoes the same expansions as if it were within dou- - ble quotes, but double quote characters in _e_x_p_r_e_s_s_i_o_n are not treated + The _e_x_p_r_e_s_s_i_o_n undergoes the same expansions as if it were within dou- + ble quotes, but double quote characters in _e_x_p_r_e_s_s_i_o_n are not treated specially and are removed. All tokens in the expression undergo param- - eter and variable expansion, command substitution, and quote removal. - The result is treated as the arithmetic expression to be evaluated. + eter and variable expansion, command substitution, and quote removal. + The result is treated as the arithmetic expression to be evaluated. Arithmetic expansions may be nested. - The evaluation is performed according to the rules listed below under + The evaluation is performed according to the rules listed below under AARRIITTHHMMEETTIICC EEVVAALLUUAATTIIOONN. If _e_x_p_r_e_s_s_i_o_n is invalid, bbaasshh prints a message indicating failure and no substitution occurs. PPrroocceessss SSuubbssttiittuuttiioonn - _P_r_o_c_e_s_s _s_u_b_s_t_i_t_u_t_i_o_n allows a process's input or output to be referred - to using a filename. It takes the form of <<((_l_i_s_t)) or >>((_l_i_s_t)). The - process _l_i_s_t is run asynchronously, and its input or output appears as + _P_r_o_c_e_s_s _s_u_b_s_t_i_t_u_t_i_o_n allows a process's input or output to be referred + to using a filename. It takes the form of <<((_l_i_s_t)) or >>((_l_i_s_t)). The + process _l_i_s_t is run asynchronously, and its input or output appears as a filename. This filename is passed as an argument to the current com- - mand as the result of the expansion. If the >>((_l_i_s_t)) form is used, - writing to the file will provide input for _l_i_s_t. If the <<((_l_i_s_t)) form - is used, the file passed as an argument should be read to obtain the + mand as the result of the expansion. If the >>((_l_i_s_t)) form is used, + writing to the file will provide input for _l_i_s_t. If the <<((_l_i_s_t)) form + is used, the file passed as an argument should be read to obtain the output of _l_i_s_t. Process substitution is supported on systems that sup- port named pipes (_F_I_F_O_s) or the //ddeevv//ffdd method of naming open files. - When available, process substitution is performed simultaneously with - parameter and variable expansion, command substitution, and arithmetic + When available, process substitution is performed simultaneously with + parameter and variable expansion, command substitution, and arithmetic expansion. WWoorrdd SSpplliittttiinngg - The shell scans the results of parameter expansion, command substitu- - tion, and arithmetic expansion that did not occur within double quotes + The shell scans the results of parameter expansion, command substitu- + tion, and arithmetic expansion that did not occur within double quotes for _w_o_r_d _s_p_l_i_t_t_i_n_g. - The shell treats each character of IIFFSS as a delimiter, and splits the - results of the other expansions into words using these characters as + The shell treats each character of IIFFSS as a delimiter, and splits the + results of the other expansions into words using these characters as field terminators. If IIFFSS is unset, or its value is exactly <><><>, the de- - fault, then sequences of ssppaaccee, ttaabb, and nneewwlliinnee at the beginning and - end of the results of the previous expansions are ignored, and any se- - quence of IIFFSS characters not at the beginning or end serves to delimit - words. If IIFFSS has a value other than the default, then sequences of - the whitespace characters ssppaaccee, ttaabb, and nneewwlliinnee are ignored at the - beginning and end of the word, as long as the whitespace character is - in the value of IIFFSS (an IIFFSS whitespace character). Any character in - IIFFSS that is not IIFFSS whitespace, along with any adjacent IIFFSS whitespace - characters, delimits a field. A sequence of IIFFSS whitespace characters + fault, then sequences of ssppaaccee, ttaabb, and nneewwlliinnee at the beginning and + end of the results of the previous expansions are ignored, and any se- + quence of IIFFSS characters not at the beginning or end serves to delimit + words. If IIFFSS has a value other than the default, then sequences of + the whitespace characters ssppaaccee, ttaabb, and nneewwlliinnee are ignored at the + beginning and end of the word, as long as the whitespace character is + in the value of IIFFSS (an IIFFSS whitespace character). Any character in + IIFFSS that is not IIFFSS whitespace, along with any adjacent IIFFSS whitespace + characters, delimits a field. A sequence of IIFFSS whitespace characters is also treated as a delimiter. - If the value of IIFFSS is null, no word splitting occurs. If IIFFSS is un- - set, word splitting behaves as if it contained the default value of + If the value of IIFFSS is null, no word splitting occurs. If IIFFSS is un- + set, word splitting behaves as if it contained the default value of <><><>. - Explicit null arguments ("""" or '''') are retained and passed to commands + Explicit null arguments ("""" or '''') are retained and passed to commands as empty strings. Unquoted implicit null arguments, resulting from the expansion of parameters that have no values, are removed. If a parame- ter with no value is expanded within double quotes, a null argument re- sults and is retained and passed to a command as an empty string. When - a quoted null argument appears as part of a word whose expansion is + a quoted null argument appears as part of a word whose expansion is non-null, the null argument is removed. That is, the word -d'' becomes -d after word splitting and null argument removal. Note that if no expansion occurs, no splitting is performed. PPaatthhnnaammee EExxppaannssiioonn - After word splitting, unless the --ff option has been set, bbaasshh scans - each word for the characters **, ??, and [[. If one of these characters + After word splitting, unless the --ff option has been set, bbaasshh scans + each word for the characters **, ??, and [[. If one of these characters appears, and is not quoted, then the word is regarded as a _p_a_t_t_e_r_n, and - replaced with an alphabetically sorted list of filenames matching the - pattern (see PPaatttteerrnn MMaattcchhiinngg below). If no matching filenames are - found, and the shell option nnuullllgglloobb is not enabled, the word is left - unchanged. If the nnuullllgglloobb option is set, and no matches are found, - the word is removed. If the ffaaiillgglloobb shell option is set, and no - matches are found, an error message is printed and the command is not + replaced with an alphabetically sorted list of filenames matching the + pattern (see PPaatttteerrnn MMaattcchhiinngg below). If no matching filenames are + found, and the shell option nnuullllgglloobb is not enabled, the word is left + unchanged. If the nnuullllgglloobb option is set, and no matches are found, + the word is removed. If the ffaaiillgglloobb shell option is set, and no + matches are found, an error message is printed and the command is not executed. If the shell option nnooccaasseegglloobb is enabled, the match is per- - formed without regard to the case of alphabetic characters. When a - pattern is used for pathname expansion, the character ````..'''' at the - start of a name or immediately following a slash must be matched ex- - plicitly, unless the shell option ddoottgglloobb is set. In order to match + formed without regard to the case of alphabetic characters. When a + pattern is used for pathname expansion, the character ````..'''' at the + start of a name or immediately following a slash must be matched ex- + plicitly, unless the shell option ddoottgglloobb is set. In order to match the filenames ````..'''' and ````....'''', the pattern must begin with ``.'' (for - example, ``.?''), even if ddoottgglloobb is set. If the gglloobbsskkiippddoottss shell - option is enabled, the filenames ````..'''' and ````....'''' are never matched, - even if the pattern begins with a ````..''''. When not matching pathnames, - the ````..'''' character is not treated specially. When matching a path- - name, the slash character must always be matched explicitly by a slash - in the pattern, but in other matching contexts it can be matched by a - special pattern character as described below under PPaatttteerrnn MMaattcchhiinngg. - See the description of sshhoopptt below under SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS for a - description of the nnooccaasseegglloobb, nnuullllgglloobb, gglloobbsskkiippddoottss, ffaaiillgglloobb, and + example, ``.?''), even if ddoottgglloobb is set. If the gglloobbsskkiippddoottss shell + option is enabled, the filenames ````..'''' and ````....'''' are never matched, + even if the pattern begins with a ````..''''. When not matching pathnames, + the ````..'''' character is not treated specially. When matching a path- + name, the slash character must always be matched explicitly by a slash + in the pattern, but in other matching contexts it can be matched by a + special pattern character as described below under PPaatttteerrnn MMaattcchhiinngg. + See the description of sshhoopptt below under SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS for a + description of the nnooccaasseegglloobb, nnuullllgglloobb, gglloobbsskkiippddoottss, ffaaiillgglloobb, and ddoottgglloobb shell options. - The GGLLOOBBIIGGNNOORREE shell variable may be used to restrict the set of file - names matching a _p_a_t_t_e_r_n. If GGLLOOBBIIGGNNOORREE is set, each matching file - name that also matches one of the patterns in GGLLOOBBIIGGNNOORREE is removed - from the list of matches. If the nnooccaasseegglloobb option is set, the match- - ing against the patterns in GGLLOOBBIIGGNNOORREE is performed without regard to + The GGLLOOBBIIGGNNOORREE shell variable may be used to restrict the set of file + names matching a _p_a_t_t_e_r_n. If GGLLOOBBIIGGNNOORREE is set, each matching file + name that also matches one of the patterns in GGLLOOBBIIGGNNOORREE is removed + from the list of matches. If the nnooccaasseegglloobb option is set, the match- + ing against the patterns in GGLLOOBBIIGGNNOORREE is performed without regard to case. The filenames ````..'''' and ````....'''' are always ignored when GGLLOOBBIIGG-- - NNOORREE is set and not null. However, setting GGLLOOBBIIGGNNOORREE to a non-null + NNOORREE is set and not null. However, setting GGLLOOBBIIGGNNOORREE to a non-null value has the effect of enabling the ddoottgglloobb shell option, so all other - filenames beginning with a ````..'''' will match. To get the old behavior - of ignoring filenames beginning with a ````..'''', make ````..**'''' one of the + filenames beginning with a ````..'''' will match. To get the old behavior + of ignoring filenames beginning with a ````..'''', make ````..**'''' one of the patterns in GGLLOOBBIIGGNNOORREE. The ddoottgglloobb option is disabled when GGLLOOBBIIGGNNOORREE is unset. The pattern matching honors the setting of the eexxttgglloobb shell option. + The GGLLOOBBSSOORRTT variable controls how the results of pathname expansion + are sorted, as described above. + PPaatttteerrnn MMaattcchhiinngg Any character that appears in a pattern, other than the special pattern @@ -4625,7 +4645,7 @@ SSHHEELLLL BBUUIILLTTIINN CCOOMMMMAANNDDSS routine call or _e_x_p_r does not correspond to a valid position in the call stack. - ccdd [--LL|[--PP [--ee]] [-@]] [_d_i_r] + ccdd [--LL|[--PP [--ee]]] [-@] [_d_i_r] Change the current directory to _d_i_r. if _d_i_r is not supplied, the value of the HHOOMMEE shell variable is the default. The vari- able CCDDPPAATTHH defines the search path for the directory containing @@ -6718,4 +6738,4 @@ BBUUGGSS -GNU Bash 5.2 2023 March 14 BASH(1) +GNU Bash 5.2 2023 April 15 BASH(1) diff --git a/doc/bash.1 b/doc/bash.1 index 0d42fcf54..1f3ce371f 100644 --- a/doc/bash.1 +++ b/doc/bash.1 @@ -5,12 +5,12 @@ .\" Case Western Reserve University .\" chet.ramey@case.edu .\" -.\" Last Change: Tue Mar 14 16:19:06 EDT 2023 +.\" Last Change: Sat Apr 15 17:52:31 EDT 2023 .\" .\" bash_builtins, strip all but Built-Ins section .if \n(zZ=1 .ig zZ .if \n(zY=1 .ig zY -.TH BASH 1 "2023 March 14" "GNU Bash 5.2" +.TH BASH 1 "2023 April 15" "GNU Bash 5.2" .\" .\" There's some problem with having a `@' .\" in a tagged paragraph with the BSD man macros. @@ -2248,6 +2248,32 @@ of the patterns in .BR GLOBIGNORE , it is removed from the list of matches. .TP +.B GLOBSORT +Control how the results of pathname expansion are sorted. +The value of this variable specifies the sort criteria and sort order for +the results of pathname expansion. +If this variable is unset or set to the null string, pathname expansion +uses the historial behavior of sorting by name. +If set, a valid value begins with an optional \fI+\fP, which is ignored, +or \fI\-\fP, which reverses the sort order from ascending to descending, +followed by a sort specifier. +The valid sort specifiers are +.IR name , +.IR size , +.IR mtime , +.IR atime , +.IR ctime , +and +.IR blocks , +which sort the files on name, file size, modification time, access time, +inode change time, and number of blocks, respectively. +For example, a value of \fB\-mtime\fP sorts the results in descending +order by modification time (newest first). +If the sort specifier is missing, it defaults to \fIname\fP, +so a value of \fI+\fP is equivalent to the null string, +and a value of \fI-\fP sorts by name in descending order. +Any invalid value restores the historical sorting behavior. +.TP .B HISTCONTROL A colon-separated list of values controlling how commands are saved on the history list. @@ -3859,6 +3885,12 @@ is unset. The pattern matching honors the setting of the \fBextglob\fP shell option. .PP +The +.SM +.B GLOBSORT +variable controls how the results of pathname expansion are sorted, as +described above. +.PP \fBPattern Matching\fP .PP Any character that appears in a pattern, other than the special pattern diff --git a/doc/bash.info b/doc/bash.info index abe9eae7c..cb40ee476 100644 --- a/doc/bash.info +++ b/doc/bash.info @@ -1,9 +1,9 @@ This is bash.info, produced by makeinfo version 6.8 from bashref.texi. This text is a brief description of the features that are present in the -Bash shell (version 5.2, 14 March 2023). +Bash shell (version 5.2, 15 April 2023). - This is Edition 5.2, last updated 14 March 2023, of 'The GNU Bash + This is Edition 5.2, last updated 15 April 2023, of 'The GNU Bash Reference Manual', for 'Bash', Version 5.2. Copyright (C) 1988-2023 Free Software Foundation, Inc. @@ -26,10 +26,10 @@ Bash Features ************* This text is a brief description of the features that are present in the -Bash shell (version 5.2, 14 March 2023). The Bash home page is +Bash shell (version 5.2, 15 April 2023). The Bash home page is . - This is Edition 5.2, last updated 14 March 2023, of 'The GNU Bash + This is Edition 5.2, last updated 15 April 2023, of 'The GNU Bash Reference Manual', for 'Bash', Version 5.2. Bash contains features that appear in other popular shells, and some @@ -2409,6 +2409,10 @@ behavior of ignoring filenames beginning with a '.', make '.*' one of the patterns in 'GLOBIGNORE'. The 'dotglob' option is disabled when 'GLOBIGNORE' is unset. + After the pattern is expanded and matched against filenames, the +value of the 'GLOBSORT' variable controls how the results are sorted, as +described below (*note Bash Variables::). +  File: bash.info, Node: Pattern Matching, Up: Filename Expansion @@ -2574,7 +2578,7 @@ was redirected to DIRLIST. Bash handles several filenames specially when they are used in redirections, as described in the following table. If the operating -system on which Bash is running provides these special files, bash will +system on which Bash is running provides these special files, Bash will use them; otherwise it will emulate them internally with the behavior described below. @@ -3249,7 +3253,7 @@ standard. than or equal to 1. 'cd' - cd [-L|[-P [-e]] [-@] [DIRECTORY] + cd [-L|[-P [-e]]] [-@] [DIRECTORY] Change the current working directory to DIRECTORY. If DIRECTORY is not supplied, the value of the 'HOME' shell variable is used. If @@ -4854,7 +4858,7 @@ This builtin allows you to change additional shell optional behavior. words to be completed. This means that dollar signs in variable names that expand to directories will not be quoted; however, any dollar signs appearing in filenames will not be - quoted, either. This is active only when bash is using + quoted, either. This is active only when Bash is using backslashes to quote completed filenames. This variable is set by default, which is the default Bash behavior in versions through 4.2. @@ -5259,7 +5263,7 @@ Variables::). 'BASH_ARGC' An array variable whose values are the number of parameters in each - frame of the current bash execution call stack. The number of + frame of the current Bash execution call stack. The number of parameters to the current subroutine (shell function or script executed with '.' or 'source') is at the top of the stack. When a subroutine is executed, the number of parameters passed is pushed @@ -5272,7 +5276,7 @@ Variables::). 'BASH_ARGV' An array variable containing all of the parameters in the current - bash execution call stack. The final parameter of the last + Bash execution call stack. The final parameter of the last subroutine call is at the top of the stack; the first parameter of the initial call is at the bottom. When a subroutine is executed, the parameters supplied are pushed onto 'BASH_ARGV'. The shell @@ -5561,6 +5565,28 @@ Variables::). 'GLOBIGNORE', it is removed from the list of matches. The pattern matching honors the setting of the 'extglob' shell option. +'GLOBSORT' + Control how the results of filename expansion are sorted. The + value of this variable specifies the sort criteria and sort order + for the results of filename expansion. If this variable is unset + or set to the null string, filename expansion uses the historial + behavior of sorting by name. If set, a valid value begins with an + optional '+', which is ignored, or '-', which reverses the sort + order from ascending to descending, followed by a sort specifier. + The valid sort specifiers are 'name', 'size', 'mtime', 'atime', + 'ctime', and 'blocks', which sort the files on name, file size, + modification time, access time, inode change time, and number of + blocks, respectively. + + For example, a value of '-mtime' sorts the results in descending + order by modification time (newest first). + + If the sort specifier is missing, it defaults to NAME, so a value + of '+' is equivalent to the null string, and a value of '-' sorts + by name in descending order. + + Any invalid value restores the historical sorting behavior. + 'GROUPS' An array variable containing the list of groups of which the current user is a member. Assignments to 'GROUPS' have no effect. @@ -6573,7 +6599,7 @@ decreasing precedence. '||' logical OR -'expr ? expr : expr' +'expr ? if-true-expr : if-false-expr' conditional operator '= *= /= %= += -= <<= >>= &= ^= |=' @@ -7069,13 +7095,60 @@ environment, such as 'jails', 'zones', or 'containers'.  File: bash.info, Node: Bash POSIX Mode, Next: Shell Compatibility Mode, Prev: The Restricted Shell, Up: Bash Features -6.11 Bash POSIX Mode -==================== +6.11 Bash and POSIX +=================== -Starting Bash with the '--posix' command-line option or executing 'set --o posix' while Bash is running will cause Bash to conform more closely -to the POSIX standard by changing the behavior to match that specified -by POSIX in areas where the Bash default differs. +6.11.1 What is POSIX? +--------------------- + +POSIX is the name for a family of standards based on Unix. A number of +Unix services, tools, and functions are part of the standard, ranging +from the basic system calls and C library functions to common +applications and tools to system administration and management. + + The POSIX Shell and Utilities standard was originally developed by +IEEE Working Group 1003.2 (POSIX.2). The first edition of the 1003.2 +standard was published in 1992. It was merged with the original IEEE +1003.1 Working Group and is currently maintained by the Austin Group (a +joint working group of the IEEE, The Open Group and ISO/IEC SC22/WG15). +Today the Shell and Utilities are a volume within the set of documents +that make up IEEE Std 1003.1-2017, and thus the former POSIX.2 (from +1992) is now part of the current unified POSIX standard. + + The Shell and Utilities volume concentrates on the command +interpreter interface and utility programs commonly executed from the +command line or by other programs. The standard is freely available on +the web at +. + + Bash is concerned with the aspects of the shell's behavior defined by +the POSIX Shell and Utilities volume. The shell command language has of +course been standardized, including the basic flow control and program +execution constructs, I/O redirection and pipelines, argument handling, +variable expansion, and quoting. + + The special builtins, which must be implemented as part of the shell +to provide the desired functionality, are specified as being part of the +shell; examples of these are 'eval' and 'export'. Other utilities +appear in the sections of POSIX not devoted to the shell which are +commonly (and in some cases must be) implemented as builtin commands, +such as 'read' and 'test'. POSIX also specifies aspects of the shell's +interactive behavior, including job control and command line editing. +Only vi-style line editing commands have been standardized; emacs +editing commands were left out due to objections. + +6.11.2 Bash POSIX Mode +---------------------- + +Although Bash is an implementation of the POSIX shell specification, +there are areas where the Bash default behavior differs from the +specification. The Bash "posix mode" changes the Bash behavior in these +areas so that it conforms to the standard more closely. + + Starting Bash with the '--posix' command-line option or executing +'set -o posix' while Bash is running will cause Bash to conform more +closely to the POSIX standard by changing the behavior to match that +specified by POSIX in areas where the Bash default differs. When invoked as 'sh', Bash enters POSIX mode after reading the startup files. @@ -7338,6 +7411,13 @@ startup files. that a backslash preceding a double quote character will escape it and the backslash will be removed. + 66. Command substitutions don't set the '?' special parameter. The + exit status of a simple command without a command word is still the + exit status of the last command substitution that occurred while + evaluating the variable assignments and redirections in that + command, but that does not happen until after all of the + assignments and redirections. + There is other POSIX behavior that Bash does not implement by default even when in POSIX mode. Specifically: @@ -7345,7 +7425,11 @@ even when in POSIX mode. Specifically: entries if 'FCEDIT' is unset, rather than defaulting directly to 'ed'. 'fc' uses 'ed' if 'EDITOR' is unset. - 2. As noted above, Bash requires the 'xpg_echo' option to be enabled + 2. A non-interactive shell does not exit if a variable assignment + preceding the 'command' builtin or another non-special builtin + fails. + + 3. As noted above, Bash requires the 'xpg_echo' option to be enabled for the 'echo' builtin to be fully conformant. Bash can be configured to be POSIX-conformant by default, by @@ -10485,7 +10569,7 @@ at the Bash prompt in your Bash source directory. If you want to build Bash in a directory separate from the source directory - to build for multiple architectures, for example - just use the full path to the configure script. The following commands will -build bash in a directory under '/usr/local/build' from the source code +build Bash in a directory under '/usr/local/build' from the source code in '/usr/local/src/bash-4.4': mkdir /usr/local/build/bash-4.4 @@ -10578,7 +10662,7 @@ By default, 'make install' will install into '/usr/local/bin', specifying a value for the 'prefix' 'make' variable when running 'make install' (e.g., 'make install prefix=PATH'). The 'prefix' variable provides a default for 'exec_prefix' and other variables used when -installing bash. +installing Bash. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you @@ -10591,7 +10675,7 @@ run, you can specify these variables as arguments to 'make': 'make install exec_prefix=/' will install 'bash' and 'bashbug' into '/bin' instead of the default '/usr/local/bin'. - If you want to see the files bash will install and where it will + If you want to see the files Bash will install and where it will install them without changing anything on your system, specify the variable 'DESTDIR' as an argument to 'make'. Its value should be the absolute directory path you'd like to use as the root of your sample @@ -10773,7 +10857,7 @@ does not provide the necessary support. builtins (*note Aliases::). '--enable-alt-array-implementation' - This builds bash using an alternate implementation of arrays (*note + This builds Bash using an alternate implementation of arrays (*note Arrays::) that provides faster access at the expense of using more memory (sometimes many times more, depending on how sparse an array is). @@ -10824,7 +10908,7 @@ does not provide the necessary support. (*note Pipelines::). '--enable-debugger' - Include support for the bash debugger (distributed separately). + Include support for the Bash debugger (distributed separately). '--enable-dev-fd-stat-broken' If calling 'stat' on /dev/fd/N returns different results than @@ -10962,11 +11046,11 @@ of Bash. The latest version of Bash is always available for FTP from . Once you have determined that a bug actually exists, use the -'bashbug' command to submit a bug report or use the form at the Bash project page. -If you have a fix, you are encouraged to submit that as well! -Suggestions and 'philosophical' bug reports may be mailed to - or . +'bashbug' command to submit a bug report or use the form at the Bash +project page (https://savannah.gnu.org/projects/bash/). If you have a +fix, you are encouraged to submit that as well! Suggestions and +'philosophical' bug reports may be mailed to or +. All bug reports should include: * The version number of Bash. @@ -12110,57 +12194,58 @@ D.3 Parameter and Variable Index * FUNCNAME: Bash Variables. (line 326) * FUNCNEST: Bash Variables. (line 343) * GLOBIGNORE: Bash Variables. (line 348) -* GROUPS: Bash Variables. (line 355) -* histchars: Bash Variables. (line 361) -* HISTCMD: Bash Variables. (line 376) -* HISTCONTROL: Bash Variables. (line 382) -* HISTFILE: Bash Variables. (line 398) -* HISTFILESIZE: Bash Variables. (line 402) -* HISTIGNORE: Bash Variables. (line 413) +* GLOBSORT: Bash Variables. (line 355) +* GROUPS: Bash Variables. (line 377) +* histchars: Bash Variables. (line 383) +* HISTCMD: Bash Variables. (line 398) +* HISTCONTROL: Bash Variables. (line 404) +* HISTFILE: Bash Variables. (line 420) +* HISTFILESIZE: Bash Variables. (line 424) +* HISTIGNORE: Bash Variables. (line 435) * history-preserve-point: Readline Init File Syntax. (line 211) * history-size: Readline Init File Syntax. (line 217) -* HISTSIZE: Bash Variables. (line 433) -* HISTTIMEFORMAT: Bash Variables. (line 440) +* HISTSIZE: Bash Variables. (line 455) +* HISTTIMEFORMAT: Bash Variables. (line 462) * HOME: Bourne Shell Variables. (line 13) * horizontal-scroll-mode: Readline Init File Syntax. (line 226) -* HOSTFILE: Bash Variables. (line 448) -* HOSTNAME: Bash Variables. (line 459) -* HOSTTYPE: Bash Variables. (line 462) +* HOSTFILE: Bash Variables. (line 470) +* HOSTNAME: Bash Variables. (line 481) +* HOSTTYPE: Bash Variables. (line 484) * IFS: Bourne Shell Variables. (line 18) -* IGNOREEOF: Bash Variables. (line 465) +* IGNOREEOF: Bash Variables. (line 487) * input-meta: Readline Init File Syntax. (line 235) -* INPUTRC: Bash Variables. (line 475) -* INSIDE_EMACS: Bash Variables. (line 479) +* INPUTRC: Bash Variables. (line 497) +* INSIDE_EMACS: Bash Variables. (line 501) * isearch-terminators: Readline Init File Syntax. (line 245) * keymap: Readline Init File Syntax. (line 252) * LANG: Creating Internationalized Scripts. (line 51) -* LANG <1>: Bash Variables. (line 485) -* LC_ALL: Bash Variables. (line 489) -* LC_COLLATE: Bash Variables. (line 493) -* LC_CTYPE: Bash Variables. (line 500) +* LANG <1>: Bash Variables. (line 507) +* LC_ALL: Bash Variables. (line 511) +* LC_COLLATE: Bash Variables. (line 515) +* LC_CTYPE: Bash Variables. (line 522) * LC_MESSAGES: Creating Internationalized Scripts. (line 51) -* LC_MESSAGES <1>: Bash Variables. (line 505) -* LC_NUMERIC: Bash Variables. (line 509) -* LC_TIME: Bash Variables. (line 513) -* LINENO: Bash Variables. (line 517) -* LINES: Bash Variables. (line 522) -* MACHTYPE: Bash Variables. (line 528) +* LC_MESSAGES <1>: Bash Variables. (line 527) +* LC_NUMERIC: Bash Variables. (line 531) +* LC_TIME: Bash Variables. (line 535) +* LINENO: Bash Variables. (line 539) +* LINES: Bash Variables. (line 544) +* MACHTYPE: Bash Variables. (line 550) * MAIL: Bourne Shell Variables. (line 22) -* MAILCHECK: Bash Variables. (line 532) +* MAILCHECK: Bash Variables. (line 554) * MAILPATH: Bourne Shell Variables. (line 27) -* MAPFILE: Bash Variables. (line 540) +* MAPFILE: Bash Variables. (line 562) * mark-modified-lines: Readline Init File Syntax. (line 282) * mark-symlinked-directories: Readline Init File Syntax. @@ -12171,46 +12256,46 @@ D.3 Parameter and Variable Index (line 299) * meta-flag: Readline Init File Syntax. (line 235) -* OLDPWD: Bash Variables. (line 544) +* OLDPWD: Bash Variables. (line 566) * OPTARG: Bourne Shell Variables. (line 34) -* OPTERR: Bash Variables. (line 547) +* OPTERR: Bash Variables. (line 569) * OPTIND: Bourne Shell Variables. (line 38) -* OSTYPE: Bash Variables. (line 551) +* OSTYPE: Bash Variables. (line 573) * output-meta: Readline Init File Syntax. (line 304) * page-completions: Readline Init File Syntax. (line 312) * PATH: Bourne Shell Variables. (line 42) -* PIPESTATUS: Bash Variables. (line 554) -* POSIXLY_CORRECT: Bash Variables. (line 559) -* PPID: Bash Variables. (line 569) -* PROMPT_COMMAND: Bash Variables. (line 573) -* PROMPT_DIRTRIM: Bash Variables. (line 579) -* PS0: Bash Variables. (line 585) +* PIPESTATUS: Bash Variables. (line 576) +* POSIXLY_CORRECT: Bash Variables. (line 581) +* PPID: Bash Variables. (line 591) +* PROMPT_COMMAND: Bash Variables. (line 595) +* PROMPT_DIRTRIM: Bash Variables. (line 601) +* PS0: Bash Variables. (line 607) * PS1: Bourne Shell Variables. (line 48) * PS2: Bourne Shell Variables. (line 53) -* PS3: Bash Variables. (line 590) -* PS4: Bash Variables. (line 595) -* PWD: Bash Variables. (line 603) -* RANDOM: Bash Variables. (line 606) -* READLINE_ARGUMENT: Bash Variables. (line 612) -* READLINE_LINE: Bash Variables. (line 616) -* READLINE_MARK: Bash Variables. (line 620) -* READLINE_POINT: Bash Variables. (line 626) -* REPLY: Bash Variables. (line 630) +* PS3: Bash Variables. (line 612) +* PS4: Bash Variables. (line 617) +* PWD: Bash Variables. (line 625) +* RANDOM: Bash Variables. (line 628) +* READLINE_ARGUMENT: Bash Variables. (line 634) +* READLINE_LINE: Bash Variables. (line 638) +* READLINE_MARK: Bash Variables. (line 642) +* READLINE_POINT: Bash Variables. (line 648) +* REPLY: Bash Variables. (line 652) * revert-all-at-newline: Readline Init File Syntax. (line 322) * search-ignore-case: Readline Init File Syntax. (line 329) -* SECONDS: Bash Variables. (line 633) -* SHELL: Bash Variables. (line 642) -* SHELLOPTS: Bash Variables. (line 647) -* SHLVL: Bash Variables. (line 656) +* SECONDS: Bash Variables. (line 655) +* SHELL: Bash Variables. (line 664) +* SHELLOPTS: Bash Variables. (line 669) +* SHLVL: Bash Variables. (line 678) * show-all-if-ambiguous: Readline Init File Syntax. (line 334) * show-all-if-unmodified: Readline Init File Syntax. @@ -12219,15 +12304,15 @@ D.3 Parameter and Variable Index (line 349) * skip-completed-text: Readline Init File Syntax. (line 355) -* SRANDOM: Bash Variables. (line 661) +* SRANDOM: Bash Variables. (line 683) * TEXTDOMAIN: Creating Internationalized Scripts. (line 51) * TEXTDOMAINDIR: Creating Internationalized Scripts. (line 51) -* TIMEFORMAT: Bash Variables. (line 670) -* TMOUT: Bash Variables. (line 708) -* TMPDIR: Bash Variables. (line 720) -* UID: Bash Variables. (line 724) +* TIMEFORMAT: Bash Variables. (line 692) +* TMOUT: Bash Variables. (line 730) +* TMPDIR: Bash Variables. (line 742) +* UID: Bash Variables. (line 746) * vi-cmd-mode-string: Readline Init File Syntax. (line 368) * vi-ins-mode-string: Readline Init File Syntax. @@ -12454,11 +12539,14 @@ D.5 Concept Index * arithmetic evaluation: Shell Arithmetic. (line 6) * arithmetic expansion: Arithmetic Expansion. (line 6) +* arithmetic operators: Shell Arithmetic. (line 17) * arithmetic, shell: Shell Arithmetic. (line 6) * arrays: Arrays. (line 6) * background: Job Control Basics. (line 6) * Bash configuration: Basic Installation. (line 6) * Bash installation: Basic Installation. (line 6) +* binary arithmetic operators: Shell Arithmetic. (line 17) +* bitwise arithmetic operators: Shell Arithmetic. (line 17) * Bourne shell: Basic Shell Features. (line 6) * brace expansion: Brace Expansion. (line 6) @@ -12492,6 +12580,7 @@ D.5 Concept Index (line 6) * completion builtins: Programmable Completion Builtins. (line 6) +* conditional arithmetic operator: Shell Arithmetic. (line 17) * configuration: Basic Installation. (line 6) * control operator: Definitions. (line 21) * coprocess: Coprocesses. (line 6) @@ -12566,7 +12655,8 @@ D.5 Concept Index * pattern matching: Pattern Matching. (line 6) * pipeline: Pipelines. (line 6) * POSIX: Definitions. (line 9) -* POSIX Mode: Bash POSIX Mode. (line 6) +* POSIX description: Bash POSIX Mode. (line 9) +* POSIX Mode: Bash POSIX Mode. (line 48) * process group: Definitions. (line 62) * process group ID: Definitions. (line 66) * process substitution: Process Substitution. @@ -12601,6 +12691,7 @@ D.5 Concept Index * tilde expansion: Tilde Expansion. (line 6) * token: Definitions. (line 86) * translation, native languages: Locale Translation. (line 6) +* unary arithmetic operators: Shell Arithmetic. (line 17) * variable, shell: Shell Parameters. (line 6) * variables, readline: Readline Init File Syntax. (line 37) @@ -12652,98 +12743,98 @@ Node: Arithmetic Expansion97645 Node: Process Substitution98610 Node: Word Splitting99727 Node: Filename Expansion101772 -Node: Pattern Matching104518 -Node: Quote Removal109517 -Node: Redirections109809 -Node: Executing Commands119499 -Node: Simple Command Expansion120166 -Node: Command Search and Execution122273 -Node: Command Execution Environment124657 -Node: Environment127689 -Node: Exit Status129349 -Node: Signals131130 -Node: Shell Scripts134576 -Node: Shell Builtin Commands137600 -Node: Bourne Shell Builtins139635 -Node: Bash Builtins161830 -Node: Modifying Shell Behavior193826 -Node: The Set Builtin194168 -Node: The Shopt Builtin204763 -Node: Special Builtins220672 -Node: Shell Variables221648 -Node: Bourne Shell Variables222082 -Node: Bash Variables224183 -Node: Bash Features256995 -Node: Invoking Bash258005 -Node: Bash Startup Files264015 -Node: Interactive Shells269143 -Node: What is an Interactive Shell?269551 -Node: Is this Shell Interactive?270197 -Node: Interactive Shell Behavior271009 -Node: Bash Conditional Expressions274635 -Node: Shell Arithmetic279274 -Node: Aliases282215 -Node: Arrays285106 -Node: The Directory Stack291666 -Node: Directory Stack Builtins292447 -Node: Controlling the Prompt296704 -Node: The Restricted Shell299666 -Node: Bash POSIX Mode302273 -Node: Shell Compatibility Mode315136 -Node: Job Control323700 -Node: Job Control Basics324157 -Node: Job Control Builtins329156 -Node: Job Control Variables334948 -Node: Command Line Editing336101 -Node: Introduction and Notation337769 -Node: Readline Interaction339389 -Node: Readline Bare Essentials340577 -Node: Readline Movement Commands342363 -Node: Readline Killing Commands343320 -Node: Readline Arguments345238 -Node: Searching346279 -Node: Readline Init File348462 -Node: Readline Init File Syntax349720 -Node: Conditional Init Constructs373508 -Node: Sample Init File377701 -Node: Bindable Readline Commands380822 -Node: Commands For Moving382023 -Node: Commands For History384071 -Node: Commands For Text389062 -Node: Commands For Killing392708 -Node: Numeric Arguments395738 -Node: Commands For Completion396874 -Node: Keyboard Macros401062 -Node: Miscellaneous Commands401747 -Node: Readline vi Mode407782 -Node: Programmable Completion408686 -Node: Programmable Completion Builtins416463 -Node: A Programmable Completion Example427212 -Node: Using History Interactively432457 -Node: Bash History Facilities433138 -Node: Bash History Builtins436140 -Node: History Interaction441161 -Node: Event Designators444778 -Node: Word Designators446129 -Node: Modifiers447886 -Node: Installing Bash449691 -Node: Basic Installation450825 -Node: Compilers and Options454544 -Node: Compiling For Multiple Architectures455282 -Node: Installation Names456971 -Node: Specifying the System Type459077 -Node: Sharing Defaults459791 -Node: Operation Controls460461 -Node: Optional Features461416 -Node: Reporting Bugs472632 -Node: Major Differences From The Bourne Shell473973 -Node: GNU Free Documentation License490819 -Node: Indexes515993 -Node: Builtin Index516444 -Node: Reserved Word Index523268 -Node: Variable Index525713 -Node: Function Index542625 -Node: Concept Index556406 +Node: Pattern Matching104702 +Node: Quote Removal109701 +Node: Redirections109993 +Node: Executing Commands119683 +Node: Simple Command Expansion120350 +Node: Command Search and Execution122457 +Node: Command Execution Environment124841 +Node: Environment127873 +Node: Exit Status129533 +Node: Signals131314 +Node: Shell Scripts134760 +Node: Shell Builtin Commands137784 +Node: Bourne Shell Builtins139819 +Node: Bash Builtins162015 +Node: Modifying Shell Behavior194011 +Node: The Set Builtin194353 +Node: The Shopt Builtin204948 +Node: Special Builtins220857 +Node: Shell Variables221833 +Node: Bourne Shell Variables222267 +Node: Bash Variables224368 +Node: Bash Features258281 +Node: Invoking Bash259291 +Node: Bash Startup Files265301 +Node: Interactive Shells270429 +Node: What is an Interactive Shell?270837 +Node: Is this Shell Interactive?271483 +Node: Interactive Shell Behavior272295 +Node: Bash Conditional Expressions275921 +Node: Shell Arithmetic280560 +Node: Aliases283518 +Node: Arrays286409 +Node: The Directory Stack292969 +Node: Directory Stack Builtins293750 +Node: Controlling the Prompt298007 +Node: The Restricted Shell300969 +Node: Bash POSIX Mode303576 +Node: Shell Compatibility Mode319366 +Node: Job Control327930 +Node: Job Control Basics328387 +Node: Job Control Builtins333386 +Node: Job Control Variables339178 +Node: Command Line Editing340331 +Node: Introduction and Notation341999 +Node: Readline Interaction343619 +Node: Readline Bare Essentials344807 +Node: Readline Movement Commands346593 +Node: Readline Killing Commands347550 +Node: Readline Arguments349468 +Node: Searching350509 +Node: Readline Init File352692 +Node: Readline Init File Syntax353950 +Node: Conditional Init Constructs377738 +Node: Sample Init File381931 +Node: Bindable Readline Commands385052 +Node: Commands For Moving386253 +Node: Commands For History388301 +Node: Commands For Text393292 +Node: Commands For Killing396938 +Node: Numeric Arguments399968 +Node: Commands For Completion401104 +Node: Keyboard Macros405292 +Node: Miscellaneous Commands405977 +Node: Readline vi Mode412012 +Node: Programmable Completion412916 +Node: Programmable Completion Builtins420693 +Node: A Programmable Completion Example431442 +Node: Using History Interactively436687 +Node: Bash History Facilities437368 +Node: Bash History Builtins440370 +Node: History Interaction445391 +Node: Event Designators449008 +Node: Word Designators450359 +Node: Modifiers452116 +Node: Installing Bash453921 +Node: Basic Installation455055 +Node: Compilers and Options458774 +Node: Compiling For Multiple Architectures459512 +Node: Installation Names461201 +Node: Specifying the System Type463307 +Node: Sharing Defaults464021 +Node: Operation Controls464691 +Node: Optional Features465646 +Node: Reporting Bugs476862 +Node: Major Differences From The Bourne Shell478193 +Node: GNU Free Documentation License495039 +Node: Indexes520213 +Node: Builtin Index520664 +Node: Reserved Word Index527488 +Node: Variable Index529933 +Node: Function Index546918 +Node: Concept Index560699  End Tag Table diff --git a/doc/bashref.info b/doc/bashref.info index c3692b943..5c023108b 100644 --- a/doc/bashref.info +++ b/doc/bashref.info @@ -2,9 +2,9 @@ This is bashref.info, produced by makeinfo version 6.8 from bashref.texi. This text is a brief description of the features that are present in the -Bash shell (version 5.2, 14 March 2023). +Bash shell (version 5.2, 15 April 2023). - This is Edition 5.2, last updated 14 March 2023, of 'The GNU Bash + This is Edition 5.2, last updated 15 April 2023, of 'The GNU Bash Reference Manual', for 'Bash', Version 5.2. Copyright (C) 1988-2023 Free Software Foundation, Inc. @@ -27,10 +27,10 @@ Bash Features ************* This text is a brief description of the features that are present in the -Bash shell (version 5.2, 14 March 2023). The Bash home page is +Bash shell (version 5.2, 15 April 2023). The Bash home page is . - This is Edition 5.2, last updated 14 March 2023, of 'The GNU Bash + This is Edition 5.2, last updated 15 April 2023, of 'The GNU Bash Reference Manual', for 'Bash', Version 5.2. Bash contains features that appear in other popular shells, and some @@ -2410,6 +2410,10 @@ behavior of ignoring filenames beginning with a '.', make '.*' one of the patterns in 'GLOBIGNORE'. The 'dotglob' option is disabled when 'GLOBIGNORE' is unset. + After the pattern is expanded and matched against filenames, the +value of the 'GLOBSORT' variable controls how the results are sorted, as +described below (*note Bash Variables::). +  File: bashref.info, Node: Pattern Matching, Up: Filename Expansion @@ -2575,7 +2579,7 @@ was redirected to DIRLIST. Bash handles several filenames specially when they are used in redirections, as described in the following table. If the operating -system on which Bash is running provides these special files, bash will +system on which Bash is running provides these special files, Bash will use them; otherwise it will emulate them internally with the behavior described below. @@ -3250,7 +3254,7 @@ standard. than or equal to 1. 'cd' - cd [-L|[-P [-e]] [-@] [DIRECTORY] + cd [-L|[-P [-e]]] [-@] [DIRECTORY] Change the current working directory to DIRECTORY. If DIRECTORY is not supplied, the value of the 'HOME' shell variable is used. If @@ -4855,7 +4859,7 @@ This builtin allows you to change additional shell optional behavior. words to be completed. This means that dollar signs in variable names that expand to directories will not be quoted; however, any dollar signs appearing in filenames will not be - quoted, either. This is active only when bash is using + quoted, either. This is active only when Bash is using backslashes to quote completed filenames. This variable is set by default, which is the default Bash behavior in versions through 4.2. @@ -5260,7 +5264,7 @@ Variables::). 'BASH_ARGC' An array variable whose values are the number of parameters in each - frame of the current bash execution call stack. The number of + frame of the current Bash execution call stack. The number of parameters to the current subroutine (shell function or script executed with '.' or 'source') is at the top of the stack. When a subroutine is executed, the number of parameters passed is pushed @@ -5273,7 +5277,7 @@ Variables::). 'BASH_ARGV' An array variable containing all of the parameters in the current - bash execution call stack. The final parameter of the last + Bash execution call stack. The final parameter of the last subroutine call is at the top of the stack; the first parameter of the initial call is at the bottom. When a subroutine is executed, the parameters supplied are pushed onto 'BASH_ARGV'. The shell @@ -5562,6 +5566,28 @@ Variables::). 'GLOBIGNORE', it is removed from the list of matches. The pattern matching honors the setting of the 'extglob' shell option. +'GLOBSORT' + Control how the results of filename expansion are sorted. The + value of this variable specifies the sort criteria and sort order + for the results of filename expansion. If this variable is unset + or set to the null string, filename expansion uses the historial + behavior of sorting by name. If set, a valid value begins with an + optional '+', which is ignored, or '-', which reverses the sort + order from ascending to descending, followed by a sort specifier. + The valid sort specifiers are 'name', 'size', 'mtime', 'atime', + 'ctime', and 'blocks', which sort the files on name, file size, + modification time, access time, inode change time, and number of + blocks, respectively. + + For example, a value of '-mtime' sorts the results in descending + order by modification time (newest first). + + If the sort specifier is missing, it defaults to NAME, so a value + of '+' is equivalent to the null string, and a value of '-' sorts + by name in descending order. + + Any invalid value restores the historical sorting behavior. + 'GROUPS' An array variable containing the list of groups of which the current user is a member. Assignments to 'GROUPS' have no effect. @@ -6574,7 +6600,7 @@ decreasing precedence. '||' logical OR -'expr ? expr : expr' +'expr ? if-true-expr : if-false-expr' conditional operator '= *= /= %= += -= <<= >>= &= ^= |=' @@ -7070,13 +7096,60 @@ environment, such as 'jails', 'zones', or 'containers'.  File: bashref.info, Node: Bash POSIX Mode, Next: Shell Compatibility Mode, Prev: The Restricted Shell, Up: Bash Features -6.11 Bash POSIX Mode -==================== +6.11 Bash and POSIX +=================== -Starting Bash with the '--posix' command-line option or executing 'set --o posix' while Bash is running will cause Bash to conform more closely -to the POSIX standard by changing the behavior to match that specified -by POSIX in areas where the Bash default differs. +6.11.1 What is POSIX? +--------------------- + +POSIX is the name for a family of standards based on Unix. A number of +Unix services, tools, and functions are part of the standard, ranging +from the basic system calls and C library functions to common +applications and tools to system administration and management. + + The POSIX Shell and Utilities standard was originally developed by +IEEE Working Group 1003.2 (POSIX.2). The first edition of the 1003.2 +standard was published in 1992. It was merged with the original IEEE +1003.1 Working Group and is currently maintained by the Austin Group (a +joint working group of the IEEE, The Open Group and ISO/IEC SC22/WG15). +Today the Shell and Utilities are a volume within the set of documents +that make up IEEE Std 1003.1-2017, and thus the former POSIX.2 (from +1992) is now part of the current unified POSIX standard. + + The Shell and Utilities volume concentrates on the command +interpreter interface and utility programs commonly executed from the +command line or by other programs. The standard is freely available on +the web at +. + + Bash is concerned with the aspects of the shell's behavior defined by +the POSIX Shell and Utilities volume. The shell command language has of +course been standardized, including the basic flow control and program +execution constructs, I/O redirection and pipelines, argument handling, +variable expansion, and quoting. + + The special builtins, which must be implemented as part of the shell +to provide the desired functionality, are specified as being part of the +shell; examples of these are 'eval' and 'export'. Other utilities +appear in the sections of POSIX not devoted to the shell which are +commonly (and in some cases must be) implemented as builtin commands, +such as 'read' and 'test'. POSIX also specifies aspects of the shell's +interactive behavior, including job control and command line editing. +Only vi-style line editing commands have been standardized; emacs +editing commands were left out due to objections. + +6.11.2 Bash POSIX Mode +---------------------- + +Although Bash is an implementation of the POSIX shell specification, +there are areas where the Bash default behavior differs from the +specification. The Bash "posix mode" changes the Bash behavior in these +areas so that it conforms to the standard more closely. + + Starting Bash with the '--posix' command-line option or executing +'set -o posix' while Bash is running will cause Bash to conform more +closely to the POSIX standard by changing the behavior to match that +specified by POSIX in areas where the Bash default differs. When invoked as 'sh', Bash enters POSIX mode after reading the startup files. @@ -7339,6 +7412,13 @@ startup files. that a backslash preceding a double quote character will escape it and the backslash will be removed. + 66. Command substitutions don't set the '?' special parameter. The + exit status of a simple command without a command word is still the + exit status of the last command substitution that occurred while + evaluating the variable assignments and redirections in that + command, but that does not happen until after all of the + assignments and redirections. + There is other POSIX behavior that Bash does not implement by default even when in POSIX mode. Specifically: @@ -7346,7 +7426,11 @@ even when in POSIX mode. Specifically: entries if 'FCEDIT' is unset, rather than defaulting directly to 'ed'. 'fc' uses 'ed' if 'EDITOR' is unset. - 2. As noted above, Bash requires the 'xpg_echo' option to be enabled + 2. A non-interactive shell does not exit if a variable assignment + preceding the 'command' builtin or another non-special builtin + fails. + + 3. As noted above, Bash requires the 'xpg_echo' option to be enabled for the 'echo' builtin to be fully conformant. Bash can be configured to be POSIX-conformant by default, by @@ -10486,7 +10570,7 @@ at the Bash prompt in your Bash source directory. If you want to build Bash in a directory separate from the source directory - to build for multiple architectures, for example - just use the full path to the configure script. The following commands will -build bash in a directory under '/usr/local/build' from the source code +build Bash in a directory under '/usr/local/build' from the source code in '/usr/local/src/bash-4.4': mkdir /usr/local/build/bash-4.4 @@ -10579,7 +10663,7 @@ By default, 'make install' will install into '/usr/local/bin', specifying a value for the 'prefix' 'make' variable when running 'make install' (e.g., 'make install prefix=PATH'). The 'prefix' variable provides a default for 'exec_prefix' and other variables used when -installing bash. +installing Bash. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you @@ -10592,7 +10676,7 @@ run, you can specify these variables as arguments to 'make': 'make install exec_prefix=/' will install 'bash' and 'bashbug' into '/bin' instead of the default '/usr/local/bin'. - If you want to see the files bash will install and where it will + If you want to see the files Bash will install and where it will install them without changing anything on your system, specify the variable 'DESTDIR' as an argument to 'make'. Its value should be the absolute directory path you'd like to use as the root of your sample @@ -10774,7 +10858,7 @@ does not provide the necessary support. builtins (*note Aliases::). '--enable-alt-array-implementation' - This builds bash using an alternate implementation of arrays (*note + This builds Bash using an alternate implementation of arrays (*note Arrays::) that provides faster access at the expense of using more memory (sometimes many times more, depending on how sparse an array is). @@ -10825,7 +10909,7 @@ does not provide the necessary support. (*note Pipelines::). '--enable-debugger' - Include support for the bash debugger (distributed separately). + Include support for the Bash debugger (distributed separately). '--enable-dev-fd-stat-broken' If calling 'stat' on /dev/fd/N returns different results than @@ -10963,11 +11047,11 @@ of Bash. The latest version of Bash is always available for FTP from . Once you have determined that a bug actually exists, use the -'bashbug' command to submit a bug report or use the form at the Bash project page. -If you have a fix, you are encouraged to submit that as well! -Suggestions and 'philosophical' bug reports may be mailed to - or . +'bashbug' command to submit a bug report or use the form at the Bash +project page (https://savannah.gnu.org/projects/bash/). If you have a +fix, you are encouraged to submit that as well! Suggestions and +'philosophical' bug reports may be mailed to or +. All bug reports should include: * The version number of Bash. @@ -12111,57 +12195,58 @@ D.3 Parameter and Variable Index * FUNCNAME: Bash Variables. (line 326) * FUNCNEST: Bash Variables. (line 343) * GLOBIGNORE: Bash Variables. (line 348) -* GROUPS: Bash Variables. (line 355) -* histchars: Bash Variables. (line 361) -* HISTCMD: Bash Variables. (line 376) -* HISTCONTROL: Bash Variables. (line 382) -* HISTFILE: Bash Variables. (line 398) -* HISTFILESIZE: Bash Variables. (line 402) -* HISTIGNORE: Bash Variables. (line 413) +* GLOBSORT: Bash Variables. (line 355) +* GROUPS: Bash Variables. (line 377) +* histchars: Bash Variables. (line 383) +* HISTCMD: Bash Variables. (line 398) +* HISTCONTROL: Bash Variables. (line 404) +* HISTFILE: Bash Variables. (line 420) +* HISTFILESIZE: Bash Variables. (line 424) +* HISTIGNORE: Bash Variables. (line 435) * history-preserve-point: Readline Init File Syntax. (line 211) * history-size: Readline Init File Syntax. (line 217) -* HISTSIZE: Bash Variables. (line 433) -* HISTTIMEFORMAT: Bash Variables. (line 440) +* HISTSIZE: Bash Variables. (line 455) +* HISTTIMEFORMAT: Bash Variables. (line 462) * HOME: Bourne Shell Variables. (line 13) * horizontal-scroll-mode: Readline Init File Syntax. (line 226) -* HOSTFILE: Bash Variables. (line 448) -* HOSTNAME: Bash Variables. (line 459) -* HOSTTYPE: Bash Variables. (line 462) +* HOSTFILE: Bash Variables. (line 470) +* HOSTNAME: Bash Variables. (line 481) +* HOSTTYPE: Bash Variables. (line 484) * IFS: Bourne Shell Variables. (line 18) -* IGNOREEOF: Bash Variables. (line 465) +* IGNOREEOF: Bash Variables. (line 487) * input-meta: Readline Init File Syntax. (line 235) -* INPUTRC: Bash Variables. (line 475) -* INSIDE_EMACS: Bash Variables. (line 479) +* INPUTRC: Bash Variables. (line 497) +* INSIDE_EMACS: Bash Variables. (line 501) * isearch-terminators: Readline Init File Syntax. (line 245) * keymap: Readline Init File Syntax. (line 252) * LANG: Creating Internationalized Scripts. (line 51) -* LANG <1>: Bash Variables. (line 485) -* LC_ALL: Bash Variables. (line 489) -* LC_COLLATE: Bash Variables. (line 493) -* LC_CTYPE: Bash Variables. (line 500) +* LANG <1>: Bash Variables. (line 507) +* LC_ALL: Bash Variables. (line 511) +* LC_COLLATE: Bash Variables. (line 515) +* LC_CTYPE: Bash Variables. (line 522) * LC_MESSAGES: Creating Internationalized Scripts. (line 51) -* LC_MESSAGES <1>: Bash Variables. (line 505) -* LC_NUMERIC: Bash Variables. (line 509) -* LC_TIME: Bash Variables. (line 513) -* LINENO: Bash Variables. (line 517) -* LINES: Bash Variables. (line 522) -* MACHTYPE: Bash Variables. (line 528) +* LC_MESSAGES <1>: Bash Variables. (line 527) +* LC_NUMERIC: Bash Variables. (line 531) +* LC_TIME: Bash Variables. (line 535) +* LINENO: Bash Variables. (line 539) +* LINES: Bash Variables. (line 544) +* MACHTYPE: Bash Variables. (line 550) * MAIL: Bourne Shell Variables. (line 22) -* MAILCHECK: Bash Variables. (line 532) +* MAILCHECK: Bash Variables. (line 554) * MAILPATH: Bourne Shell Variables. (line 27) -* MAPFILE: Bash Variables. (line 540) +* MAPFILE: Bash Variables. (line 562) * mark-modified-lines: Readline Init File Syntax. (line 282) * mark-symlinked-directories: Readline Init File Syntax. @@ -12172,46 +12257,46 @@ D.3 Parameter and Variable Index (line 299) * meta-flag: Readline Init File Syntax. (line 235) -* OLDPWD: Bash Variables. (line 544) +* OLDPWD: Bash Variables. (line 566) * OPTARG: Bourne Shell Variables. (line 34) -* OPTERR: Bash Variables. (line 547) +* OPTERR: Bash Variables. (line 569) * OPTIND: Bourne Shell Variables. (line 38) -* OSTYPE: Bash Variables. (line 551) +* OSTYPE: Bash Variables. (line 573) * output-meta: Readline Init File Syntax. (line 304) * page-completions: Readline Init File Syntax. (line 312) * PATH: Bourne Shell Variables. (line 42) -* PIPESTATUS: Bash Variables. (line 554) -* POSIXLY_CORRECT: Bash Variables. (line 559) -* PPID: Bash Variables. (line 569) -* PROMPT_COMMAND: Bash Variables. (line 573) -* PROMPT_DIRTRIM: Bash Variables. (line 579) -* PS0: Bash Variables. (line 585) +* PIPESTATUS: Bash Variables. (line 576) +* POSIXLY_CORRECT: Bash Variables. (line 581) +* PPID: Bash Variables. (line 591) +* PROMPT_COMMAND: Bash Variables. (line 595) +* PROMPT_DIRTRIM: Bash Variables. (line 601) +* PS0: Bash Variables. (line 607) * PS1: Bourne Shell Variables. (line 48) * PS2: Bourne Shell Variables. (line 53) -* PS3: Bash Variables. (line 590) -* PS4: Bash Variables. (line 595) -* PWD: Bash Variables. (line 603) -* RANDOM: Bash Variables. (line 606) -* READLINE_ARGUMENT: Bash Variables. (line 612) -* READLINE_LINE: Bash Variables. (line 616) -* READLINE_MARK: Bash Variables. (line 620) -* READLINE_POINT: Bash Variables. (line 626) -* REPLY: Bash Variables. (line 630) +* PS3: Bash Variables. (line 612) +* PS4: Bash Variables. (line 617) +* PWD: Bash Variables. (line 625) +* RANDOM: Bash Variables. (line 628) +* READLINE_ARGUMENT: Bash Variables. (line 634) +* READLINE_LINE: Bash Variables. (line 638) +* READLINE_MARK: Bash Variables. (line 642) +* READLINE_POINT: Bash Variables. (line 648) +* REPLY: Bash Variables. (line 652) * revert-all-at-newline: Readline Init File Syntax. (line 322) * search-ignore-case: Readline Init File Syntax. (line 329) -* SECONDS: Bash Variables. (line 633) -* SHELL: Bash Variables. (line 642) -* SHELLOPTS: Bash Variables. (line 647) -* SHLVL: Bash Variables. (line 656) +* SECONDS: Bash Variables. (line 655) +* SHELL: Bash Variables. (line 664) +* SHELLOPTS: Bash Variables. (line 669) +* SHLVL: Bash Variables. (line 678) * show-all-if-ambiguous: Readline Init File Syntax. (line 334) * show-all-if-unmodified: Readline Init File Syntax. @@ -12220,15 +12305,15 @@ D.3 Parameter and Variable Index (line 349) * skip-completed-text: Readline Init File Syntax. (line 355) -* SRANDOM: Bash Variables. (line 661) +* SRANDOM: Bash Variables. (line 683) * TEXTDOMAIN: Creating Internationalized Scripts. (line 51) * TEXTDOMAINDIR: Creating Internationalized Scripts. (line 51) -* TIMEFORMAT: Bash Variables. (line 670) -* TMOUT: Bash Variables. (line 708) -* TMPDIR: Bash Variables. (line 720) -* UID: Bash Variables. (line 724) +* TIMEFORMAT: Bash Variables. (line 692) +* TMOUT: Bash Variables. (line 730) +* TMPDIR: Bash Variables. (line 742) +* UID: Bash Variables. (line 746) * vi-cmd-mode-string: Readline Init File Syntax. (line 368) * vi-ins-mode-string: Readline Init File Syntax. @@ -12455,11 +12540,14 @@ D.5 Concept Index * arithmetic evaluation: Shell Arithmetic. (line 6) * arithmetic expansion: Arithmetic Expansion. (line 6) +* arithmetic operators: Shell Arithmetic. (line 17) * arithmetic, shell: Shell Arithmetic. (line 6) * arrays: Arrays. (line 6) * background: Job Control Basics. (line 6) * Bash configuration: Basic Installation. (line 6) * Bash installation: Basic Installation. (line 6) +* binary arithmetic operators: Shell Arithmetic. (line 17) +* bitwise arithmetic operators: Shell Arithmetic. (line 17) * Bourne shell: Basic Shell Features. (line 6) * brace expansion: Brace Expansion. (line 6) @@ -12493,6 +12581,7 @@ D.5 Concept Index (line 6) * completion builtins: Programmable Completion Builtins. (line 6) +* conditional arithmetic operator: Shell Arithmetic. (line 17) * configuration: Basic Installation. (line 6) * control operator: Definitions. (line 21) * coprocess: Coprocesses. (line 6) @@ -12567,7 +12656,8 @@ D.5 Concept Index * pattern matching: Pattern Matching. (line 6) * pipeline: Pipelines. (line 6) * POSIX: Definitions. (line 9) -* POSIX Mode: Bash POSIX Mode. (line 6) +* POSIX description: Bash POSIX Mode. (line 9) +* POSIX Mode: Bash POSIX Mode. (line 48) * process group: Definitions. (line 62) * process group ID: Definitions. (line 66) * process substitution: Process Substitution. @@ -12602,6 +12692,7 @@ D.5 Concept Index * tilde expansion: Tilde Expansion. (line 6) * token: Definitions. (line 86) * translation, native languages: Locale Translation. (line 6) +* unary arithmetic operators: Shell Arithmetic. (line 17) * variable, shell: Shell Parameters. (line 6) * variables, readline: Readline Init File Syntax. (line 37) @@ -12653,98 +12744,98 @@ Node: Arithmetic Expansion97756 Node: Process Substitution98724 Node: Word Splitting99844 Node: Filename Expansion101892 -Node: Pattern Matching104641 -Node: Quote Removal109643 -Node: Redirections109938 -Node: Executing Commands119631 -Node: Simple Command Expansion120301 -Node: Command Search and Execution122411 -Node: Command Execution Environment124798 -Node: Environment127833 -Node: Exit Status129496 -Node: Signals131280 -Node: Shell Scripts134729 -Node: Shell Builtin Commands137756 -Node: Bourne Shell Builtins139794 -Node: Bash Builtins161992 -Node: Modifying Shell Behavior193991 -Node: The Set Builtin194336 -Node: The Shopt Builtin204934 -Node: Special Builtins220846 -Node: Shell Variables221825 -Node: Bourne Shell Variables222262 -Node: Bash Variables224366 -Node: Bash Features257181 -Node: Invoking Bash258194 -Node: Bash Startup Files264207 -Node: Interactive Shells269338 -Node: What is an Interactive Shell?269749 -Node: Is this Shell Interactive?270398 -Node: Interactive Shell Behavior271213 -Node: Bash Conditional Expressions274842 -Node: Shell Arithmetic279484 -Node: Aliases282428 -Node: Arrays285322 -Node: The Directory Stack291885 -Node: Directory Stack Builtins292669 -Node: Controlling the Prompt296929 -Node: The Restricted Shell299894 -Node: Bash POSIX Mode302504 -Node: Shell Compatibility Mode315370 -Node: Job Control323937 -Node: Job Control Basics324397 -Node: Job Control Builtins329399 -Node: Job Control Variables335194 -Node: Command Line Editing336350 -Node: Introduction and Notation338021 -Node: Readline Interaction339644 -Node: Readline Bare Essentials340835 -Node: Readline Movement Commands342624 -Node: Readline Killing Commands343584 -Node: Readline Arguments345505 -Node: Searching346549 -Node: Readline Init File348735 -Node: Readline Init File Syntax349996 -Node: Conditional Init Constructs373787 -Node: Sample Init File377983 -Node: Bindable Readline Commands381107 -Node: Commands For Moving382311 -Node: Commands For History384362 -Node: Commands For Text389356 -Node: Commands For Killing393005 -Node: Numeric Arguments396038 -Node: Commands For Completion397177 -Node: Keyboard Macros401368 -Node: Miscellaneous Commands402056 -Node: Readline vi Mode408094 -Node: Programmable Completion409001 -Node: Programmable Completion Builtins416781 -Node: A Programmable Completion Example427533 -Node: Using History Interactively432781 -Node: Bash History Facilities433465 -Node: Bash History Builtins436470 -Node: History Interaction441494 -Node: Event Designators445114 -Node: Word Designators446468 -Node: Modifiers448228 -Node: Installing Bash450036 -Node: Basic Installation451173 -Node: Compilers and Options454895 -Node: Compiling For Multiple Architectures455636 -Node: Installation Names457328 -Node: Specifying the System Type459437 -Node: Sharing Defaults460154 -Node: Operation Controls460827 -Node: Optional Features461785 -Node: Reporting Bugs473004 -Node: Major Differences From The Bourne Shell474348 -Node: GNU Free Documentation License491197 -Node: Indexes516374 -Node: Builtin Index516828 -Node: Reserved Word Index523655 -Node: Variable Index526103 -Node: Function Index543018 -Node: Concept Index556802 +Node: Pattern Matching104825 +Node: Quote Removal109827 +Node: Redirections110122 +Node: Executing Commands119815 +Node: Simple Command Expansion120485 +Node: Command Search and Execution122595 +Node: Command Execution Environment124982 +Node: Environment128017 +Node: Exit Status129680 +Node: Signals131464 +Node: Shell Scripts134913 +Node: Shell Builtin Commands137940 +Node: Bourne Shell Builtins139978 +Node: Bash Builtins162177 +Node: Modifying Shell Behavior194176 +Node: The Set Builtin194521 +Node: The Shopt Builtin205119 +Node: Special Builtins221031 +Node: Shell Variables222010 +Node: Bourne Shell Variables222447 +Node: Bash Variables224551 +Node: Bash Features258467 +Node: Invoking Bash259480 +Node: Bash Startup Files265493 +Node: Interactive Shells270624 +Node: What is an Interactive Shell?271035 +Node: Is this Shell Interactive?271684 +Node: Interactive Shell Behavior272499 +Node: Bash Conditional Expressions276128 +Node: Shell Arithmetic280770 +Node: Aliases283731 +Node: Arrays286625 +Node: The Directory Stack293188 +Node: Directory Stack Builtins293972 +Node: Controlling the Prompt298232 +Node: The Restricted Shell301197 +Node: Bash POSIX Mode303807 +Node: Shell Compatibility Mode319600 +Node: Job Control328167 +Node: Job Control Basics328627 +Node: Job Control Builtins333629 +Node: Job Control Variables339424 +Node: Command Line Editing340580 +Node: Introduction and Notation342251 +Node: Readline Interaction343874 +Node: Readline Bare Essentials345065 +Node: Readline Movement Commands346854 +Node: Readline Killing Commands347814 +Node: Readline Arguments349735 +Node: Searching350779 +Node: Readline Init File352965 +Node: Readline Init File Syntax354226 +Node: Conditional Init Constructs378017 +Node: Sample Init File382213 +Node: Bindable Readline Commands385337 +Node: Commands For Moving386541 +Node: Commands For History388592 +Node: Commands For Text393586 +Node: Commands For Killing397235 +Node: Numeric Arguments400268 +Node: Commands For Completion401407 +Node: Keyboard Macros405598 +Node: Miscellaneous Commands406286 +Node: Readline vi Mode412324 +Node: Programmable Completion413231 +Node: Programmable Completion Builtins421011 +Node: A Programmable Completion Example431763 +Node: Using History Interactively437011 +Node: Bash History Facilities437695 +Node: Bash History Builtins440700 +Node: History Interaction445724 +Node: Event Designators449344 +Node: Word Designators450698 +Node: Modifiers452458 +Node: Installing Bash454266 +Node: Basic Installation455403 +Node: Compilers and Options459125 +Node: Compiling For Multiple Architectures459866 +Node: Installation Names461558 +Node: Specifying the System Type463667 +Node: Sharing Defaults464384 +Node: Operation Controls465057 +Node: Optional Features466015 +Node: Reporting Bugs477234 +Node: Major Differences From The Bourne Shell478568 +Node: GNU Free Documentation License495417 +Node: Indexes520594 +Node: Builtin Index521048 +Node: Reserved Word Index527875 +Node: Variable Index530323 +Node: Function Index547311 +Node: Concept Index561095  End Tag Table diff --git a/doc/bashref.texi b/doc/bashref.texi index e058c9b9b..7ed8ec86e 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -2838,6 +2838,10 @@ To get the old behavior of ignoring filenames beginning with a The @code{dotglob} option is disabled when @env{GLOBIGNORE} is unset. +After the pattern is expanded and matched against filenames, the value of the +@env{GLOBSORT} variable controls how the results are sorted, as described +below (@pxref{Bash Variables}). + @node Pattern Matching @subsubsection Pattern Matching @cindex pattern matching @@ -6467,6 +6471,35 @@ of matches. The pattern matching honors the setting of the @code{extglob} shell option. +@item GLOBSORT +Control how the results of filename expansion are sorted. +The value of this variable specifies the sort criteria and sort order for +the results of filename expansion. +If this variable is unset or set to the null string, filename expansion +uses the historial behavior of sorting by name. +If set, a valid value begins with an optional @samp{+}, which is ignored, +or @samp{-}, which reverses the sort order from ascending to descending, +followed by a sort specifier. +The valid sort specifiers are +@samp{name}, +@samp{size}, +@samp{mtime}, +@samp{atime}, +@samp{ctime}, +and +@samp{blocks}, +which sort the files on name, file size, modification time, access time, +inode change time, and number of blocks, respectively. + +For example, a value of @code{-mtime} sorts the results in descending +order by modification time (newest first). + +If the sort specifier is missing, it defaults to @var{name}, +so a value of @samp{+} is equivalent to the null string, +and a value of @samp{-} sorts by name in descending order. + +Any invalid value restores the historical sorting behavior. + @item GROUPS An array variable containing the list of groups of which the current user is a member. diff --git a/doc/version.texi b/doc/version.texi index 928b9836b..3918a4bf1 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -2,10 +2,10 @@ Copyright (C) 1988-2023 Free Software Foundation, Inc. @end ignore -@set LASTCHANGE Thu Apr 6 11:58:41 EDT 2023 +@set LASTCHANGE Sat Apr 15 17:27:25 EDT 2023 @set EDITION 5.2 @set VERSION 5.2 -@set UPDATED 6 April 2023 +@set UPDATED 15 April 2023 @set UPDATED-MONTH April 2023 diff --git a/examples/loadables/getconf.c b/examples/loadables/getconf.c index 0dc213be9..27a04dcfd 100644 --- a/examples/loadables/getconf.c +++ b/examples/loadables/getconf.c @@ -43,6 +43,11 @@ extern int errno; #define VAL_SSIZE_MAX -1004 #define VAL_SIZE_MAX -1005 +/* We don't want to collide with anything else. */ +#ifndef _CS_PATH +#define _CS_PATH -1001 +#endif + struct conf { const char *name; @@ -916,6 +921,31 @@ static int getconf_all (void); static int getconf_one (WORD_LIST *); static int getconf_internal (const struct conf *, int); +#ifndef HAVE_CONFSTR +/* If we don't have confstr, this will only support `getconf PATH'. */ + +static size_t +confstr (int name, char *buf, size_t len) +{ + char *p; + size_t n; + + switch (name) + { + case _CS_PATH: + p = conf_standard_path (); + n = STRLEN (p) + 1; + if (len != 0 && buf != 0) + strlcpy (buf, p, len); + free (p); + return n; + default: + errno = EINVAL; + return 0; + } +} +#endif /* !HAVE_CONFSTR */ + static int getconf_internal (const struct conf *c, int all) { diff --git a/externs.h b/externs.h index 7c70da927..3eb49ecbb 100644 --- a/externs.h +++ b/externs.h @@ -179,6 +179,10 @@ extern void show_shell_version (int); /* Functions from the bash library, lib/sh/libsh.a. These should really go into a separate include file. */ +/* declarations for functions defined in lib/sh/anonfile.c */ +extern int anonopen (const char *, int); +extern int anonclose (int, const char *); + /* declarations for functions defined in lib/sh/casemod.c */ extern char *sh_modcase (const char *, char *, int); @@ -496,6 +500,7 @@ extern void print_timeval (FILE *, struct timeval *); #define MT_READWRITE 0x0002 #define MT_USERANDOM 0x0004 #define MT_TEMPLATE 0x0008 +#define MT_UNLINK 0x0010 /* unlink after opening */ extern char *sh_mktmpname (const char *, int); extern int sh_mktmpfd (const char *, int, char **); diff --git a/lib/readline/examples/excallback.c b/lib/readline/examples/excallback.c index 923c9238b..04ecb1408 100644 --- a/lib/readline/examples/excallback.c +++ b/lib/readline/examples/excallback.c @@ -102,7 +102,7 @@ cc_t old_vtime; struct termios term; int -main() +main(int c, char **v) { fd_set fds; diff --git a/lib/readline/examples/fileman.c b/lib/readline/examples/fileman.c index 2a8b097ad..c14fe3bf5 100644 --- a/lib/readline/examples/fileman.c +++ b/lib/readline/examples/fileman.c @@ -1,6 +1,6 @@ /* fileman.c - file manager example for readline library. */ -/* Copyright (C) 1987-2009 Free Software Foundation, Inc. +/* Copyright (C) 1987-2009,2023 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -61,24 +61,24 @@ # include #endif -extern char *xmalloc PARAMS((size_t)); +extern char *xmalloc (size_t); -void initialize_readline PARAMS((void)); -void too_dangerous PARAMS((char *)); +void initialize_readline (void); +void too_dangerous (char *); -int execute_line PARAMS((char *)); -int valid_argument PARAMS((char *, char *)); +int execute_line (char *); +int valid_argument (char *, char *); /* The names of functions that actually do the manipulation. */ -int com_list PARAMS((char *)); -int com_view PARAMS((char *)); -int com_rename PARAMS((char *)); -int com_stat PARAMS((char *)); -int com_pwd PARAMS((char *)); -int com_delete PARAMS((char *)); -int com_help PARAMS((char *)); -int com_cd PARAMS((char *)); -int com_quit PARAMS((char *)); +int com_list (char *); +int com_view (char *); +int com_rename (char *); +int com_stat (char *); +int com_pwd (char *); +int com_delete (char *); +int com_help (char *); +int com_cd (char *); +int com_quit (char *); /* A structure which contains information on the commands this program can understand. */ @@ -105,8 +105,11 @@ COMMAND commands[] = { }; /* Forward declarations. */ -char *stripwhite (); -COMMAND *find_command (); +char *dupstr (char *); +int execute_line (char *); +char *stripwhite (char *); + +COMMAND *find_command (char *); /* The name of this program, as taken from argv[0]. */ char *progname; @@ -115,8 +118,7 @@ char *progname; int done; char * -dupstr (s) - char *s; +dupstr (char *s) { char *r; @@ -125,45 +127,9 @@ dupstr (s) return (r); } -int -main (argc, argv) - int argc; - char **argv; -{ - char *line, *s; - - progname = argv[0]; - - initialize_readline (); /* Bind our completer. */ - - /* Loop reading and executing lines until the user quits. */ - for ( ; done == 0; ) - { - line = readline ("FileMan: "); - - if (!line) - break; - - /* Remove leading and trailing whitespace from the line. - Then, if there is anything left, add it to the history list - and execute it. */ - s = stripwhite (line); - - if (*s) - { - add_history (s); - execute_line (s); - } - - free (line); - } - exit (0); -} - /* Execute a command line. */ int -execute_line (line) - char *line; +execute_line (char *line) { register int i; COMMAND *command; @@ -202,8 +168,7 @@ execute_line (line) /* Look up NAME as the name of a command, and return a pointer to that command. Return a NULL pointer if NAME isn't a command name. */ COMMAND * -find_command (name) - char *name; +find_command (char *name) { register int i; @@ -217,8 +182,7 @@ find_command (name) /* Strip whitespace from the start and end of STRING. Return a pointer into STRING. */ char * -stripwhite (string) - char *string; +stripwhite (char *string) { register char *s, *t; @@ -242,14 +206,14 @@ stripwhite (string) /* */ /* **************************************************************** */ -char *command_generator PARAMS((const char *, int)); -char **fileman_completion PARAMS((const char *, int, int)); +char *command_generator (const char *, int); +char **fileman_completion (const char *, int, int); /* Tell the GNU Readline library how to complete. We want to try to complete on command names if this is the first word in the line, or on filenames if not. */ void -initialize_readline () +initialize_readline (void) { /* Allow conditional parsing of the ~/.inputrc file. */ rl_readline_name = "FileMan"; @@ -264,9 +228,7 @@ initialize_readline () in case we want to do some simple parsing. Return the array of matches, or NULL if there aren't any. */ char ** -fileman_completion (text, start, end) - const char *text; - int start, end; +fileman_completion (const char *text, int start, int end) { char **matches; @@ -285,9 +247,7 @@ fileman_completion (text, start, end) to start from scratch; without any state (i.e. STATE == 0), then we start at the top of the list. */ char * -command_generator (text, state) - const char *text; - int state; +command_generator (const char *text, int state) { static int list_index, len; char *name; @@ -504,3 +464,36 @@ valid_argument (caller, arg) return (1); } + +int +main (int argc, char **argv) +{ + char *line, *s; + + progname = argv[0]; + + initialize_readline (); /* Bind our completer. */ + + /* Loop reading and executing lines until the user quits. */ + for ( ; done == 0; ) + { + line = readline ("FileMan: "); + + if (!line) + break; + + /* Remove leading and trailing whitespace from the line. + Then, if there is anything left, add it to the history list + and execute it. */ + s = stripwhite (line); + + if (*s) + { + add_history (s); + execute_line (s); + } + + free (line); + } + exit (0); +} diff --git a/lib/readline/examples/manexamp.c b/lib/readline/examples/manexamp.c index 351c6285e..c8e11d5c8 100644 --- a/lib/readline/examples/manexamp.c +++ b/lib/readline/examples/manexamp.c @@ -1,6 +1,6 @@ /* manexamp.c -- The examples which appear in the documentation are here. */ -/* Copyright (C) 1987-2009 Free Software Foundation, Inc. +/* Copyright (C) 1987-2009,2023 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -18,9 +18,35 @@ You should have received a copy of the GNU General Public License along with Readline. If not, see . */ +#if defined (HAVE_CONFIG_H) +# include +#endif +#ifdef HAVE_UNISTD_H +# include +#endif + + +#include #include -#include + +#include +#include +#include + +#include + +#ifndef errno +extern int errno; +#endif + +#if defined (READLINE_LIBRARY) +# include "readline.h" +# include "history.h" +#else +# include +# include +#endif /* **************************************************************** */ /* */ @@ -33,7 +59,7 @@ static char *line_read = (char *)NULL; /* Read a string, and return a pointer to it. Returns NULL on EOF. */ char * -rl_gets () +rl_gets (void) { /* If the buffer has already been allocated, return the memory to the free pool. */ @@ -60,10 +86,11 @@ rl_gets () /* **************************************************************** */ /* Invert the case of the COUNT following characters. */ -invert_case_line (count, key) - int count, key; +int +invert_case_line (int count, int key) { - register int start, end; + int start, end; + int direction; start = rl_point; @@ -92,7 +119,7 @@ invert_case_line (count, key) } if (start == end) - return; + return 0; /* Tell readline that we are modifying the line, so save the undo information. */ @@ -108,4 +135,5 @@ invert_case_line (count, key) /* Move point to on top of the last character changed. */ rl_point = end - direction; + return 0; } diff --git a/lib/readline/examples/rl-callbacktest2.c b/lib/readline/examples/rl-callbacktest2.c index dfaf96755..0bf0641c9 100644 --- a/lib/readline/examples/rl-callbacktest2.c +++ b/lib/readline/examples/rl-callbacktest2.c @@ -46,7 +46,7 @@ cb_linehandler (char *line) } static char * -cb_readline () +cb_readline (void) { fd_set fds; int r, err; @@ -102,15 +102,13 @@ else if (RL_ISSTATE (RL_STATE_NSEARCH)) } void -sigint_sighandler (s) - int s; +sigint_sighandler (int s) { saw_signal = s; } int -sigint_handler (s) - int s; +sigint_handler (int s) { rl_free_line_state (); rl_callback_sigcleanup (); diff --git a/lib/readline/examples/rl.c b/lib/readline/examples/rl.c index e04bbd6a5..dd8f88d49 100644 --- a/lib/readline/examples/rl.c +++ b/lib/readline/examples/rl.c @@ -59,7 +59,7 @@ static char *progname; static char *deftext; static int -set_deftext () +set_deftext (void) { if (deftext) { @@ -71,16 +71,14 @@ set_deftext () } static void -usage() +usage(void) { fprintf (stderr, "%s: usage: %s [-p prompt] [-u unit] [-d default] [-n nchars]\n", progname, progname); } int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { char *temp, *prompt; struct stat sb; diff --git a/lib/readline/examples/rlcat.c b/lib/readline/examples/rlcat.c index aabe0ca3e..419a1973a 100644 --- a/lib/readline/examples/rlcat.c +++ b/lib/readline/examples/rlcat.c @@ -4,7 +4,7 @@ * usage: rlcat */ -/* Copyright (C) 1987-2009 Free Software Foundation, Inc. +/* Copyright (C) 1987-2009,2023 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -64,27 +64,26 @@ extern int errno; extern int optind; extern char *optarg; -static int stdcat(); +static int fcopy(FILE *); +static int stdcat(int, char **); static char *progname; static int vflag; static void -usage() +usage(void) { fprintf (stderr, "%s: usage: %s [-vEVN] [filename]\n", progname, progname); } int -main (argc, argv) - int argc; - char **argv; +main (int argc, char **argv) { char *temp; int opt, Vflag, Nflag; #ifdef HAVE_SETLOCALE - setlocale (LC_ALL, ""): + setlocale (LC_ALL, ""); #endif progname = strrchr(argv[0], '/'); @@ -134,8 +133,7 @@ main (argc, argv) } static int -fcopy(fp) - FILE *fp; +fcopy(FILE *fp) { int c; char *x; @@ -155,9 +153,7 @@ fcopy(fp) } int -stdcat (argc, argv) - int argc; - char **argv; +stdcat (int argc, char **argv) { int i, fd, r; char *s; diff --git a/lib/readline/examples/rlptytest.c b/lib/readline/examples/rlptytest.c index d170f62ff..021a868b0 100644 --- a/lib/readline/examples/rlptytest.c +++ b/lib/readline/examples/rlptytest.c @@ -42,8 +42,7 @@ static int masterfd = -1; static int slavefd; void -sigint (s) - int s; +sigint (int s) { tty_reset (STDIN_FILENO); close (masterfd); @@ -53,14 +52,13 @@ sigint (s) } void -sigwinch (s) - int s; +sigwinch (int s) { rl_resize_terminal (); } static int -user_input() +user_input(void) { int size; const int MAX = 1024; @@ -78,7 +76,7 @@ user_input() } static int -readline_input() +readline_input(void) { const int MAX = 1024; char *buf = (char *)malloc(MAX+1); @@ -124,7 +122,7 @@ rlctx_send_user_command(char *line) } static void -custom_deprep_term_function () +custom_deprep_term_function (void) { } @@ -226,9 +224,10 @@ static enum { RESET, TCBREAK } ttystate = RESET; * * Returns: 0 on success, -1 on error */ -int tty_cbreak(int fd){ +int tty_cbreak(int fd) +{ struct termios buf; - int ttysavefd = -1; + int ttysavefd = -1; if(tcgetattr(fd, &save_termios) < 0) return -1; @@ -316,7 +315,7 @@ int tty_reset(int fd) } int -main() +main(int c, char **v) { int val; diff --git a/lib/readline/examples/rltest.c b/lib/readline/examples/rltest.c index 8b7c00c8c..feab90f22 100644 --- a/lib/readline/examples/rltest.c +++ b/lib/readline/examples/rltest.c @@ -4,7 +4,7 @@ /* */ /* **************************************************************** */ -/* Copyright (C) 1987-2009 Free Software Foundation, Inc. +/* Copyright (C) 1987-2009,2023 Free Software Foundation, Inc. This file is part of the GNU Readline Library (Readline), a library for reading lines of text with interactive input and history editing. @@ -48,10 +48,8 @@ extern void exit(); # include #endif -extern HIST_ENTRY **history_list (); - int -main () +main (int c, char **v) { char *temp, *prompt; int done; diff --git a/lib/sh/Makefile.in b/lib/sh/Makefile.in index b343dd66c..4d4ad17a4 100644 --- a/lib/sh/Makefile.in +++ b/lib/sh/Makefile.in @@ -94,7 +94,8 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \ wcsdup.c fpurge.c zgetline.c mbscmp.c mbsncmp.c uconvert.c \ ufuncs.c casemod.c dprintf.c input_avail.c mbscasecmp.c fnxform.c \ strchrnul.c unicode.c wcswidth.c wcsnwidth.c shmbchar.c strdup.c \ - strvis.c utf8.c random.c gettimeofday.c timers.c + strvis.c strlcpy.c strscpy.c utf8.c random.c gettimeofday.c \ + timers.c anonfile.c # The header files for this library. HSOURCES = @@ -109,6 +110,7 @@ OBJECTS = clktck.o clock.o getenv.o oslib.o setlinebuf.o strnlen.o \ fmtullong.o fmtumax.o zcatfd.o zmapfd.o winsize.o wcsdup.o \ fpurge.o zgetline.o mbscmp.o mbsncmp.o uconvert.o ufuncs.o casemod.o \ input_avail.o mbscasecmp.o fnxform.o unicode.o shmbchar.o strvis.o \ + strscpy.o anonfile.o \ utf8.o random.o gettimeofday.o timers.o wcsnwidth.o ${LIBOBJS} SUPPORT = Makefile @@ -144,6 +146,7 @@ ${BUILD_DIR}/pathnames.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile -( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} pathnames.h ) # rules for losing makes, like SunOS +anonfile.o: anonfile.c casemod.o: casemod.c clktck.o: clktck.c clock.o: clock.c @@ -200,6 +203,8 @@ strtoull.o: strtoull.c strtoumax.o: strtoumax.c strtrans.o: strtrans.c strvis.o: strvis.c +strlcpy.o: strlcpy.c +strscpy.o: strscpy.c timers.o: timers.c times.o: times.c timeval.o: timeval.c @@ -227,6 +232,7 @@ strtoul.o: strtol.c strtoull.o: strtol.c # all files in the library depend on config.h +anonfile.o: ${BUILD_DIR}/config.h casemod.o: ${BUILD_DIR}/config.h clktck.o: ${BUILD_DIR}/config.h clock.o: ${BUILD_DIR}/config.h @@ -283,6 +289,8 @@ strtoull.o: ${BUILD_DIR}/config.h strtoumax.o: ${BUILD_DIR}/config.h strtrans.o: ${BUILD_DIR}/config.h strvis.o: ${BUILD_DIR}/config.h +strlcpy.o: ${BUILD_DIR}/config.h +strscpy.o: ${BUILD_DIR}/config.h timers.o: ${BUILD_DIR}/config.h times.o: ${BUILD_DIR}/config.h timeval.o: ${BUILD_DIR}/config.h @@ -521,6 +529,14 @@ strvis.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h strvis.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h strvis.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h +strlcpy.o: ${topdir}/bashansi.h +strlcpy.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h +strlcpy.o: ${BASHINCDIR}/typemax.h + +strscpy.o: ${topdir}/bashansi.h +strscpy.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h +strscpy.o: ${BASHINCDIR}/typemax.h + times.o: ${BASHINCDIR}/systimes.h times.o: ${BASHINCDIR}/posixtime.h @@ -539,7 +555,6 @@ tmpfile.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h tmpfile.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h tmpfile.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h -uconvert.o: ${topdir}/bashtypes.h uconvert.o: ${BASHINCDIR}/chartypes.h uconvert.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h uconvert.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h @@ -662,3 +677,14 @@ zmapfd.o: ${BASHINCDIR}/stdc.h zmapfd.o: ${topdir}/command.h zmapfd.o: ${topdir}/general.h zmapfd.o: ${topdir}/bashtypes.h ${BASHINCDIR}/chartypes.h ${topdir}/xmalloc.h + +anonfile.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h +anonfile.o: ${topdir}/bashtypes.h +anonfile.o: ${BASHINCDIR}/filecntl.h +anonfile.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h +anonfile.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h +anonfile.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${topdir}/conftypes.h +anonfile.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h +anonfile.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h +anonfile.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h +anonfile.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h diff --git a/lib/sh/anonfile.c b/lib/sh/anonfile.c new file mode 100644 index 000000000..ded456b5e --- /dev/null +++ b/lib/sh/anonfile.c @@ -0,0 +1,67 @@ +/* anonfile.c - open and close temporary files (anonymous and memory-backed if possible). */ + +/* Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see . +*/ + +#include + +#if defined (HAVE_UNISTD_H) +# include +#endif +#include + +#if defined (HAVE_MEMFD_CREATE) || defined (HAVE_SHM_OPEN) || defined (HAVE_SHM_MKSTEMP) +# include +#endif +#include + +#include + +#include +#include + +/* Placeholder for future use of memfd_create/shm_open/shm_mkstemp */ + +static int +anonunlink (const char *fn) +{ + int r; + + r = unlink (fn); + return r; +} + +int +anonopen (const char *name, int flags) +{ + int fd, flag; + + /* Heuristic */ + flag = (name && *name == '/') ? MT_TEMPLATE : MT_USETMPDIR; + fd = sh_mktmpfd (name, flag|MT_USERANDOM|MT_READWRITE|MT_UNLINK, (char **)NULL); + return fd; +} + +int +anonclose (int fd, const char *name) +{ + int r; + + r = close (fd); + return r; +} diff --git a/lib/sh/strlcpy.c b/lib/sh/strlcpy.c new file mode 100644 index 000000000..9781c3f40 --- /dev/null +++ b/lib/sh/strlcpy.c @@ -0,0 +1,39 @@ +/* strlcpy - null-terminated string copy with length checking. */ + +/* Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see . +*/ + +#include + +#include + +size_t +strlcpy(const char *dest, const const char *src, size_t size) +{ + size_t ret; + + ret = strlen(src); + if (size) + { + size_t len; + len = (ret >= size) ? size - 1 : ret; + memcpy (dest, src, len); + dest[len] = '\0'; + } + return ret; +} diff --git a/lib/sh/strscpy.c b/lib/sh/strscpy.c new file mode 100644 index 000000000..7a948ebec --- /dev/null +++ b/lib/sh/strscpy.c @@ -0,0 +1,38 @@ +/* strscpy - null-terminated string copy with length checking. */ + +/* Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of GNU Bash, the Bourne Again SHell. + + Bash is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Bash is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Bash. If not, see . +*/ + +#include + +#include + +ssize_t +strscpy (char *d, const char *s, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) + if ((d[i] = s[i]) == 0) + return ((ssize_t)i); + + if (i != 0) + d[--i] = '\0'; + + return (-1); /* strlen (s) > len */ +} diff --git a/lib/sh/tmpfile.c b/lib/sh/tmpfile.c index 502676096..83e368496 100644 --- a/lib/sh/tmpfile.c +++ b/lib/sh/tmpfile.c @@ -58,6 +58,8 @@ extern int errno; extern pid_t dollar_dollar_pid; +static int tmpunlink (const char *); + static char *get_sys_tmpdir (void); static char *get_tmpdir (int); @@ -134,6 +136,15 @@ sh_seedrand (void) #endif } +static int +tmpunlink (const char *fn) +{ + int r; + + r = unlink (fn); + return r; +} + char * sh_mktmpname (const char *nameroot, int flags) { @@ -181,7 +192,7 @@ sh_mktmpname (const char *nameroot, int flags) (unsigned long) dollar_dollar_pid ^ x; sprintf (filename, "%s/%s-%lu", tdir, lroot, filenum); - if (tmpnamelen > 0 && tmpnamelen < 32) + if (tmpnamelen > 0 && tmpnamelen < 32) /* XXX */ filename[tdlen + 1 + tmpnamelen] = '\0'; # ifdef HAVE_LSTAT r = lstat (filename, &sb); @@ -220,6 +231,13 @@ sh_mktmpfd (const char *nameroot, int flags, char **namep) else sprintf (filename, "%s/%s.XXXXXX", tdir, lroot); fd = mkstemp (filename); + if ((flags & MT_UNLINK) && tmpunlink (filename) < 0) + { + int e = errno; + close (fd); + fd = -1; + errno = e; + } if (fd < 0 || namep == 0) { free (filename); @@ -227,6 +245,7 @@ sh_mktmpfd (const char *nameroot, int flags, char **namep) } if (namep) *namep = filename; + return fd; #else /* !USE_MKSTEMP */ #ifndef USE_URANDOM32 @@ -245,16 +264,27 @@ sh_mktmpfd (const char *nameroot, int flags, char **namep) (unsigned long) dollar_dollar_pid ^ x; sprintf (filename, "%s/%s-%lu", tdir, lroot, filenum); - if (tmpnamelen > 0 && tmpnamelen < 32) + if (tmpnamelen > 0 && tmpnamelen < 32) /* XXX */ filename[tdlen + 1 + tmpnamelen] = '\0'; fd = open (filename, BASEOPENFLAGS | ((flags & MT_READWRITE) ? O_RDWR : O_WRONLY), 0600); } while (fd < 0 && errno == EEXIST); + if ((flags & MT_UNLINK) && (tmpunlink (filename) < 0) + { + int e = errno; + close (fd); + fd = -1; + errno = e; + } + if (fd < 0 || namep == 0) + { + free (filename); + filename = NULL; + } + if (namep) *namep = filename; - else - free (filename); return fd; #endif /* !USE_MKSTEMP */ diff --git a/parse.y b/parse.y index e70b340d4..d05f0a61b 100644 --- a/parse.y +++ b/parse.y @@ -381,6 +381,8 @@ static FILE *yyerrstream; /* Special; never created by yylex; only set by parse_comsub and xparse_dolparen */ %token DOLPAREN +/* Special; never created by yylex; only set by parse_matched_pair/parse_comsub/xparse_dolparen */ +%token DOLBRACE /* The types that the various syntactical units return. */ @@ -1041,6 +1043,14 @@ comsub: DOLPAREN compound_list ')' { $$ = (COMMAND *)NULL; } + | DOLBRACE compound_list '}' + { + $$ = $2; + } + | DOLBRACE newline_list '}' + { + $$ = (COMMAND *)NULL; + } ; coproc: COPROC shell_command diff --git a/pathexp.c b/pathexp.c index 38e5b8a01..21eed3835 100644 --- a/pathexp.c +++ b/pathexp.c @@ -27,6 +27,9 @@ # include #endif +#include "posixstat.h" +#include "stat-time.h" + #include "bashansi.h" #include "shell.h" @@ -36,11 +39,13 @@ #include "shmbutil.h" #include "bashintl.h" + #include static int glob_name_is_acceptable (const char *); static void ignore_globbed_names (char **, sh_ignore_func_t *); static char *split_ignorespec (char *, int *); +static void sh_sortglob (char **); #include @@ -396,7 +401,8 @@ quote_globbing_chars (const char *string) return temp; } -/* Call the glob library to do globbing on PATHNAME. */ +/* Call the glob library to do globbing on PATHNAME, honoring all the shell + variables that control globbing. */ char ** shell_glob_filename (const char *pathname, int qflags) { @@ -415,7 +421,7 @@ shell_glob_filename (const char *pathname, int qflags) if (should_ignore_glob_matches ()) ignore_glob_matches (results); if (results && results[0]) - strvec_sort (results, 1); /* posix sort */ + sh_sortglob (results); else { FREE (results); @@ -426,6 +432,28 @@ shell_glob_filename (const char *pathname, int qflags) return (results); } +#if defined (READLINE) && defined (PROGRAMMABLE_COMPLETION) +char ** +noquote_glob_filename (char *pathname) +{ + char **results; + int gflags; + + noglob_dot_filenames = glob_dot_filenames == 0; + gflags = glob_star ? GX_GLOBSTAR : 0; + + results = glob_filename (pathname, gflags); + + if (results && GLOB_FAILED (results)) + results = (char **)NULL; + + if (results && results[0]) + sh_sortglob (results); + + return (results); +} +#endif + /* Stuff for GLOBIGNORE. */ static struct ignorevar globignore = @@ -615,3 +643,210 @@ setup_ignore_patterns (struct ignorevar *ivp) ivp->ignores[numitems].val = (char *)NULL; ivp->num_ignores = numitems; } + +/* Functions to handle sorting glob results in different ways depending on + the value of the GLOBSORT variable. */ + +static int glob_sorttype = STAT_NONE; + +static STRING_INT_ALIST sorttypes[] = { + { "name", STAT_NAME }, + { "size", STAT_SIZE }, + { "mtime", STAT_MTIME }, + { "atime", STAT_ATIME }, + { "ctime", STAT_CTIME }, + { "blocks", STAT_BLOCKS }, + { (char *)NULL, -1 } +}; + +/* A subset of the fields in the posix stat struct -- the ones we need -- + normalized to using struct timespec. */ +struct globstat { + off_t size; + struct timespec mtime; + struct timespec atime; + struct timespec ctime; + int blocks; +}; + +struct globsort_t { + char *name; + struct globstat st; +}; + +static struct globstat glob_nullstat = { -1, { -1, -1 }, { -1, -1 }, { -1, -1 }, -1 }; + +static inline int +glob_findtype (char *t) +{ + int type; + + type = find_string_in_alist (t, sorttypes, 0); + return (type == -1 ? STAT_NONE : type); +} + +void +setup_globsort (const char *varname) +{ + char *val; + int r, t; + + glob_sorttype = STAT_NONE; + val = get_string_value (varname); + if (val == 0 || *val == 0) + return; + + t = r = 0; + while (*val && whitespace (*val)) + val++; /* why not? */ + if (*val == '+') + val++; /* allow leading `+' but ignore it */ + else if (*val == '-') + { + r = STAT_REVERSE; /* leading `-' reverses sort order */ + val++; + } + + if (*val == 0) + { + /* A bare `+' means the default sort by name in ascending order; a bare + `-' means to sort by name in descending order. */ + glob_sorttype = STAT_NAME | r; + return; + } + + t = glob_findtype (val); + /* any other value is equivalent to the historical behavior */ + glob_sorttype = (t == STAT_NONE) ? t : t | r; +} + +static int +globsort_namecmp (char **s1, char **s2) +{ + return ((glob_sorttype < STAT_REVERSE) ? strvec_posixcmp (s1, s2) : strvec_posixcmp (s2, s1)); +} + +static int +globsort_sizecmp (struct globsort_t *g1, struct globsort_t *g2) +{ + return ((glob_sorttype < STAT_REVERSE) ? g1->st.size - g2->st.size : g2->st.size - g1->st.size); +} + +static int +globsort_timecmp (struct globsort_t *g1, struct globsort_t *g2) +{ + int t; + struct timespec t1, t2; + + t = (glob_sorttype < STAT_REVERSE) ? glob_sorttype : glob_sorttype - STAT_REVERSE; + if (t == STAT_MTIME) + { + t1 = g1->st.mtime; + t2 = g2->st.mtime; + } + else if (t == STAT_ATIME) + { + t1 = g1->st.atime; + t2 = g2->st.atime; + } + else + { + t1 = g1->st.ctime; + t2 = g2->st.ctime; + } + + return ((glob_sorttype < STAT_REVERSE) ? timespec_cmp (t1, t2) : timespec_cmp (t2, t1)); +} + +static int +globsort_blockscmp (struct globsort_t *g1, struct globsort_t *g2) +{ + return ((glob_sorttype < STAT_REVERSE) ? g1->st.blocks - g2->st.blocks : g2->st.blocks - g1->st.blocks); +} + +static struct globsort_t * +globsort_buildarray (char **array, size_t len) +{ + struct globsort_t *ret; + int i; + struct stat st; + + ret = (struct globsort_t *)xmalloc (len * sizeof (struct globsort_t)); + + for (i = 0; i < len; i++) + { + ret[i].name = array[i]; + if (stat (array[i], &st) != 0) + ret[i].st = glob_nullstat; + else + { + ret[i].st.size = st.st_size; + ret[i].st.mtime = get_stat_mtime (&st); + ret[i].st.atime = get_stat_atime (&st); + ret[i].st.ctime = get_stat_ctime (&st); + ret[i].st.blocks = st.st_blocks; + } + } + + return ret; +} + +static inline void +globsort_sortbyname (char **results) +{ + qsort (results, strvec_len (results), sizeof (char *), (QSFUNC *)globsort_namecmp); +} + +static void +globsort_sortarray (struct globsort_t *garray, size_t len) +{ + int t; + QSFUNC *sortfunc; + + t = (glob_sorttype < STAT_REVERSE) ? glob_sorttype : glob_sorttype - STAT_REVERSE; + + switch (t) + { + case STAT_SIZE: + sortfunc = (QSFUNC *)globsort_sizecmp; + break; + case STAT_ATIME: + case STAT_MTIME: + case STAT_CTIME: + sortfunc = (QSFUNC *)globsort_timecmp; + break; + case STAT_BLOCKS: + sortfunc = (QSFUNC *)globsort_blockscmp; + break; + default: + internal_error (_("invalid glob sort type")); + break; + } + + qsort (garray, len, sizeof (struct globsort_t), sortfunc); +} + +static void +sh_sortglob (char **results) +{ + size_t rlen; + struct globsort_t *garray; + + if (glob_sorttype == STAT_NONE || glob_sorttype == STAT_NAME) + globsort_sortbyname (results); /* posix sort */ + else if (glob_sorttype == (STAT_NAME|STAT_REVERSE)) + globsort_sortbyname (results); /* posix sort reverse order */ + else + { + int i; + + rlen = strvec_len (results); + /* populate an array of name/statinfo, sort it appropriately, copy the + names from the sorted array back to RESULTS, and free the array */ + garray = globsort_buildarray (results, rlen); + globsort_sortarray (garray, rlen); + for (i = 0; i < rlen; i++) + results[i] = garray[i].name; + free (garray); + } +} diff --git a/pathexp.h b/pathexp.h index 6a549912e..87da5f9e9 100644 --- a/pathexp.h +++ b/pathexp.h @@ -71,6 +71,8 @@ extern char *quote_globbing_chars (const char *); whether or not we've already performed quote removal. */ extern char **shell_glob_filename (const char *, int); +extern char **noquote_glob_filename (char *); + /* Filename completion ignore. Used to implement the "fignore" facility of tcsh, GLOBIGNORE (like ksh-93 FIGNORE), and EXECIGNORE. @@ -102,4 +104,17 @@ extern void setup_glob_ignore (const char *); extern int should_ignore_glob_matches (void); extern void ignore_glob_matches (char **); +/* Definitions for glob sorting */ +#define STAT_NONE 0 +#define STAT_NAME 1 +#define STAT_SIZE 2 +#define STAT_MTIME 3 +#define STAT_ATIME 4 +#define STAT_CTIME 5 +#define STAT_BLOCKS 6 + +#define STAT_REVERSE 128 + +extern void setup_globsort (const char *); + #endif diff --git a/pcomplete.c b/pcomplete.c index 553623d58..b1c5a3714 100644 --- a/pcomplete.c +++ b/pcomplete.c @@ -849,14 +849,9 @@ static STRINGLIST * gen_globpat_matches (COMPSPEC *cs, const char *text) { STRINGLIST *sl; - int gflags; - noglob_dot_filenames = glob_dot_filenames == 0; - gflags = glob_star ? GX_GLOBSTAR : 0; sl = strlist_create (0); - sl->list = glob_filename (cs->globpat, gflags); - if (GLOB_FAILED (sl->list)) - sl->list = (char **)NULL; + sl->list = noquote_glob_filename (cs->globpat); if (sl->list) sl->list_len = sl->list_size = strvec_len (sl->list); return sl; @@ -1484,6 +1479,7 @@ pcomp_set_readline_variables (int flags, int nval) option is supposed to turn it off */ if (flags & COPT_NOQUOTE) rl_filename_quoting_desired = 1 - nval; + /* Ditto */ if (flags & COPT_NOSORT) rl_sort_completion_matches = 1 - nval; } diff --git a/po/hr.gmo b/po/hr.gmo index 2ac09d966..afd51b02c 100644 Binary files a/po/hr.gmo and b/po/hr.gmo differ diff --git a/po/hr.po b/po/hr.po index 9b34f029d..65e1aba8d 100644 --- a/po/hr.po +++ b/po/hr.po @@ -3,13 +3,13 @@ # This file is distributed under the same license as the bash package. # # Tomislav Krznar , 2012, 2013. -# Božidar Putanec , 2018, 2019, 2020, 2021, 2022. +# Božidar Putanec , 2018, 2019, 2020, 2021, 2022, 2023. msgid "" msgstr "" -"Project-Id-Version: bash 5.2-rc1\n" +"Project-Id-Version: bash-5.2-rc1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-01-11 14:50-0500\n" -"PO-Revision-Date: 2022-06-17 11:19-0700\n" +"PO-Revision-Date: 2023-04-12 12:19-0700\n" "Last-Translator: Božidar Putanec \n" "Language-Team: Croatian \n" "Language: hr\n" @@ -18,7 +18,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "X-Bugs: Report translation errors to the Language-Team address.\n" -"X-Generator: Lokalize 22.07.70\n" +"X-Generator: Poedit 3.2.2\n" #: arrayfunc.c:66 msgid "bad array subscript" @@ -3736,8 +3736,8 @@ msgstr "" " Varijable, za upotrebu u izrazima, ne moraju imati atribut cijelog broja.\n" "\n" " Operatori se vrednuju prema pravilima prednosti. Najprije se\n" -" vrednuju pod-izrazi u zagradama i tako mogu prevagnuti nad gore\n" -" opisanim pravilima prednosti.\n" +" vrednuju pod-izrazi u zagradama i tako mogu redefinirati gore\n" +" opisana pravilila prednosti.\n" "\n" " Ako je vrednovanje zadnjeg ARGUMENTA nula (0), „let“ završi s kȏdom 1;\n" " inače završi s uspjehom." diff --git a/variables.c b/variables.c index 868b34b08..9d9c8a438 100644 --- a/variables.c +++ b/variables.c @@ -5639,6 +5639,7 @@ static struct name_and_function special_vars[] = { { "FUNCNEST", sv_funcnest }, { "GLOBIGNORE", sv_globignore }, + { "GLOBSORT", sv_globsort }, #if defined (HISTORY) { "HISTCONTROL", sv_history_control }, @@ -5833,6 +5834,13 @@ sv_globignore (const char *name) setup_glob_ignore (name); } +/* What to do when GLOBSORT changes. */ +void +sv_globsort (const char *name) +{ + setup_globsort (name); +} + #if defined (READLINE) void sv_comp_wordbreaks (const char *name) diff --git a/variables.h b/variables.h index f469a3f30..576796e84 100644 --- a/variables.h +++ b/variables.h @@ -431,6 +431,7 @@ extern void sv_opterr (const char *); extern void sv_locale (const char *); extern void sv_xtracefd (const char *); extern void sv_shcompat (const char *); +extern void sv_globsort (const char *); #if defined (READLINE) extern void sv_comp_wordbreaks (const char *);