Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Annotated List of Bash Enhancements

News Bash Recommended books Recommended links BASH Prompt Control Symbols Reference bash Tips and Tricks
Bash 4.3 Bash 4.2 Bash 4.1 Bash 4.0 Bash 3.2 Bash 3.1 Bash3.0
Bash 2.05a Bash 2.05b Bash 2.05 Bash 2.04 Bash 2.03 Bash 2.02 Bash 2.01 Differences
from Born shell
Etc

FSF/Gnu project does extremely dismal job in maintaining and enhancing of key GNU stack applications. Bash is a classic example of semi-abandoned application that does not get the appropriate amount of funding from FSF.

RMS should be held responsible for this "dereliction of duty" and prohibited from traveling abroad for at least a year ;-).

As support from FSF is almost non-existent development is rather slow. Still for the last ten years substantial progress was made and bash 3.2 looks like a pretty promising enterprise-class shell both for interactive work and for simple scripting. Still problems remain. One of the most acute is treatment of the last stage of the pipe as a different process (the major incompatibility with ksh and ksh93).

Some interesting features of bash include:

Due to this bash shell is gradually gaining grounds as the preferred interactive shell for Solaris and other enterprize class Unixes.

Older version of bash (2.x series) are obsolete and should not be used. The recommended version is 3.2 patch level 3 or above. The latter is a recommended version as it's more compatible with ksh93. It supports many important enhancements introduced by ksh93.


Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

[Dec 06, 2015] Bash For Loop Examples

A very nice tutorial by Vivek Gite (created October 31, 2008 last updated June 24, 2015). His mistake is putting new for loop too far inside the tutorial. It should emphazied, not hidden.
June 24, 2015 | cyberciti.biz

... ... ...

Bash v4.0+ has inbuilt support for setting up a step value using {START..END..INCREMENT} syntax:

#!/bin/bash
echo "Bash version ${BASH_VERSION}..."
for i in {0..10..2}
  do
     echo "Welcome $i times"
 done

Sample outputs:

Bash version 4.0.33(0)-release...
Welcome 0 times
Welcome 2 times
Welcome 4 times
Welcome 6 times
Welcome 8 times
Welcome 10 times

... ... ...

Three-expression bash for loops syntax

This type of for loop share a common heritage with the C programming language. It is characterized by a three-parameter loop control expression; consisting of an initializer (EXP1), a loop-test or condition (EXP2), and a counting expression (EXP3).

for (( EXP1; EXP2; EXP3 ))
do
	command1
	command2
	command3
done

A representative three-expression example in bash as follows:

#!/bin/bash
for (( c=1; c<=5; c++ ))
do
   echo "Welcome $c times"
done
... ... ...

Jadu Saikia, November 2, 2008, 3:37 pm

Nice one. All the examples are explained well, thanks Vivek.

seq 1 2 20
output can also be produced using jot

jot – 1 20 2

The infinite loops as everyone knows have the following alternatives.

while(true)
or
while :

//Jadu

Andi Reinbrech, November 18, 2010, 7:42 pm
I know this is an ancient thread, but thought this trick might be helpful to someone:

For the above example with all the cuts, simply do

set `echo $line`

This will split line into positional parameters and you can after the set simply say

F1=$1; F2=$2; F3=$3

I used this a lot many years ago on solaris with "set `date`", it neatly splits the whole date string into variables and saves lots of messy cutting :-)

… no, you can't change the FS, if it's not space, you can't use this method

Peko, July 16, 2009, 6:11 pm
Hi Vivek,
Thanks for this a useful topic.

IMNSHO, there may be something to modify here
=======================
Latest bash version 3.0+ has inbuilt support for setting up a step value:

#!/bin/bash
for i in {1..5}
=======================
1) The increment feature seems to belong to the version 4 of bash.
Reference: http://bash-hackers.org/wiki/doku.php/syntax/expansion/brace
Accordingly, my bash v3.2 does not include this feature.

BTW, where did you read that it was 3.0+ ?
(I ask because you may know some good website of interest on the subject).

2) The syntax is {from..to..step} where from, to, step are 3 integers.
You code is missing the increment.

Note that GNU Bash documentation may be bugged at this time,
because on GNU Bash manual, you will find the syntax {x..y[incr]}
which may be a typo. (missing the second ".." between y and increment).

see http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion

The Bash Hackers page
again, see http://bash-hackers.org/wiki/doku.php/syntax/expansion/brace
seeems to be more accurate,
but who knows ? Anyway, at least one of them may be right… ;-)

Keep on the good work of your own,
Thanks a million.

- Peko

Michal Kaut July 22, 2009, 6:12 am
Hello,

is there a simple way to control the number formatting? I use several computers, some of which have non-US settings with comma as a decimal point. This means that
for x in $(seq 0 0.1 1) gives 0 0.1 0.2 … 1 one some machines and 0 0,1 0,2 … 1 on other.
Is there a way to force the first variant, regardless of the language settings? Can I, for example, set the keyboard to US inside the script? Or perhaps some alternative to $x that would convert commas to points?
(I am sending these as parameters to another code and it won't accept numbers with commas…)

The best thing I could think of is adding x=`echo $x | sed s/,/./` as a first line inside the loop, but there should be a better solution? (Interestingly, the sed command does not seem to be upset by me rewriting its variable.)

Thanks,
Michal

Peko July 22, 2009, 7:27 am

To Michal Kaut:

Hi Michal,

Such output format is configured through LOCALE settings.

I tried :

export LC_CTYPE="en_EN.UTF-8″; seq 0 0.1 1

and it works as desired.

You just have to find the exact value for LC_CTYPE that fits to your systems and your needs.

Peko

Peko July 22, 2009, 2:29 pm

To Michal Kaus [2]

Ooops – ;-)
Instead of LC_CTYPE,
LC_NUMERIC should be more appropriate
(Although LC_CTYPE is actually yielding to the same result – I tested both)

By the way, Vivek has already documented the matter : http://www.cyberciti.biz/tips/linux-find-supportable-character-sets.html

Philippe Petrinko October 30, 2009, 8:35 am

To Vivek:
Regarding your last example, that is : running a loop through arguments given to the script on the command line, there is a simplier way of doing this:
# instead of:
# FILES="$@"
# for f in $FILES

# use the following syntax
for arg
do
# whatever you need here – try : echo "$arg"
done

Of course, you can use any variable name, not only "arg".

Philippe Petrinko November 11, 2009, 11:25 am

To tdurden:

Why would'nt you use

1) either a [for] loop
for old in * ; do mv ${old} ${old}.new; done

2) Either the [rename] command ?
excerpt form "man rename" :

RENAME(1) Perl Programmers Reference Guide RENAME(1)

NAME
rename – renames multiple files

SYNOPSIS
rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

DESCRIPTION
"rename" renames the filenames supplied according to the rule specified
as the first argument. The perlexpr argument is a Perl expression
which is expected to modify the $_ string in Perl for at least some of
the filenames specified. If a given filename is not modified by the
expression, it will not be renamed. If no filenames are given on the
command line, filenames will be read via standard input.

For example, to rename all files matching "*.bak" to strip the
extension, you might say

rename 's/\.bak$//' *.bak

To translate uppercase names to lower, you'd use

rename 'y/A-Z/a-z/' *

- Philippe

Philippe Petrinko November 11, 2009, 9:27 pm

If you set the shell option extglob, Bash understands some more powerful patterns. Here, a is one or more pattern, separated by the pipe-symbol (|).

?() Matches zero or one occurrence of the given patterns
*() Matches zero or more occurrences of the given patterns
+() Matches one or more occurrences of the given patterns
@() Matches one of the given patterns
!() Matches anything except one of the given patterns

source: http://www.bash-hackers.org/wiki/doku.php/syntax/pattern

Philippe Petrinko November 12, 2009, 3:44 pm

To Sean:
Right, the more sharp a knife is, the easier it can cut your fingers…

I mean: There are side-effects to the use of file globbing (like in [ for f in * ] ) , when the globbing expression matches nothing: the globbing expression is not susbtitued.

Then you might want to consider using [ nullglob ] shell extension,
to prevent this.
see: http://www.bash-hackers.org/wiki/doku.php/syntax/expansion/globs#customization

Devil hides in detail ;-)

Dominic January 14, 2010, 10:04 am

There is an interesting difference between the exit value for two different for looping structures (hope this comes out right):
for (( c=1; c<=2; c++ )) do echo -n "inside (( )) loop c is $c, "; done; echo "done (( )) loop c is $c"
for c in {1..2}; do echo -n "inside { } loop c is $c, "; done; echo "done { } loop c is $c"

You see that the first structure does a final increment of c, the second does not. The first is more useful IMO because if you have a conditional break in the for loop, then you can subsequently test the value of $c to see if the for loop was broken or not; with the second structure you can't know whether the loop was broken on the last iteration or continued to completion.

Dominic January 14, 2010, 10:09 am

sorry, my previous post would have been clearer if I had shown the output of my code snippet, which is:
inside (( )) loop c is 1, inside (( )) loop c is 2, done (( )) loop c is 3
inside { } loop c is 1, inside { } loop c is 2, done { } loop c is 2

Philippe Petrinko March 9, 2010, 2:34 pm

@Dmitry

And, again, as stated many times up there, using [seq] is counter productive, because it requires a call to an external program, when you should Keep It Short and Simple, using only bash internals functions:


for ((c=1; c<21; c+=2)); do echo "Welcome $c times" ; done

(and I wonder why Vivek is sticking to that old solution which should be presented only for historical reasons when there was no way of using bash internals.
By the way, this historical recall should be placed only at topic end, and not on top of the topic, which makes newbies sticking to the not-up-to-date technique ;-) )

Sean March 9, 2010, 11:15 pm

I have a comment to add about using the builtin for (( … )) syntax. I would agree the builtin method is cleaner, but from what I've noticed with other builtin functionality, I had to check the speed advantage for myself. I wrote the following files:

builtin_count.sh:

#!/bin/bash
for ((i=1;i<=1000000;i++))
do
echo "Output $i"
done

seq_count.sh:

#!/bin/bash
for i in $(seq 1 1000000)
do
echo "Output $i"
done

And here were the results that I got:
time ./builtin_count.sh
real 0m22.122s
user 0m18.329s
sys 0m3.166s

time ./seq_count.sh
real 0m19.590s
user 0m15.326s
sys 0m2.503s

The performance increase isn't too significant, especially when you are probably going to be doing something a little more interesting inside of the for loop, but it does show that builtin commands are not necessarily faster.

Andi Reinbrech November 18, 2010, 8:35 pm

The reason why the external seq is faster, is because it is executed only once, and returns a huge splurb of space separated integers which need no further processing, apart from the for loop advancing to the next one for the variable substitution.

The internal loop is a nice and clean/readable construct, but it has a lot of overhead. The check expression is re-evaluated on every iteration, and a variable on the interpreter's heap gets incremented, possibly checked for overflow etc. etc.

Note that the check expression cannot be simplified or internally optimised by the interpreter because the value may change inside the loop's body (yes, there are cases where you'd want to do this, however rare and stupid they may seem), hence the variables are volatile and get re-evaluted.

I.e. botom line, the internal one has more overhead, the "seq" version is equivalent to either having 1000000 integers inside the script (hard coded), or reading once from a text file with 1000000 integers with a cat. Point being that it gets executed only once and becomes static.

OK, blah blah fishpaste, past my bed time :-)

Cheers,
Andi

Anthony Thyssen June 4, 2010, 6:53 am

The {1..10} syntax is pretty useful as you can use a variable with it!

limit=10
echo {1..${limit}}
{1..10}

You need to eval it to get it to work!

limit=10
eval "echo {1..${limit}}"
1 2 3 4 5 6 7 8 9 10

'seq' is not avilable on ALL system (MacOSX for example)
and BASH is not available on all systems either.

You are better off either using the old while-expr method for computer compatiblity!

   limit=10; n=1;
   while [ $n -le 10 ]; do
     echo $n;
     n=`expr $n + 1`;
   done

Alternativally use a seq() function replacement…

 # seq_count 10
seq_count() {
  i=1; while [ $i -le $1 ]; do echo $i; i=`expr $i + 1`; done
}
# simple_seq 1 2 10
simple_seq() {
  i=$1; while [ $i -le $3 ]; do echo $i; i=`expr $i + $2`; done
}
seq_integer() {
    if [ "X$1" = "X-f" ]
    then format="$2"; shift; shift
    else format="%d"
    fi
    case $# in
    1) i=1 inc=1 end=$1 ;;
    2) i=$1 inc=1 end=$2 ;;
    *) i=$1 inc=$2 end=$3 ;;
    esac
    while [ $i -le $end ]; do
      printf "$format\n" $i;
      i=`expr $i + $inc`;
    done
  }

Edited: by Admin – added code tags.

TheBonsai June 4, 2010, 9:57 am

The Bash C-style for loop was taken from KSH93, thus I guess it's at least portable towards Korn and Z.

The seq-function above could use i=$((i + inc)), if only POSIX matters. expr is obsolete for those things, even in POSIX.

Philippe Petrinko June 4, 2010, 10:15 am

Right Bonsai,
( http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_04 )

But FOR C-style does not seem to be POSIXLY-correct…

Read on-line reference issue 6/2004,
Top is here, http://www.opengroup.org/onlinepubs/009695399/mindex.html

and the Shell and Utilities volume (XCU) T.OC. is here
http://www.opengroup.org/onlinepubs/009695399/utilities/toc.html
doc is:
http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap01.html

and FOR command:
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_04_03

Anthony Thyssen June 6, 2010, 7:18 am

TheBonsai wrote…. "The seq-function above could use i=$((i + inc)), if only POSIX matters. expr is obsolete for those things, even in POSIX."

I am not certain it is in Posix. It was NOT part of the original Bourne Shell, and on some machines, I deal with Bourne Shell. Not Ksh, Bash, or anything else.

Bourne Shell syntax works everywhere! But as 'expr' is a builtin in more modern shells, then it is not a big loss or slow down.

This is especially important if writing a replacement command, such as for "seq" where you want your "just-paste-it-in" function to work as widely as possible.

I have been shell programming pretty well all the time since 1988, so I know what I am talking about! Believe me.

MacOSX has in this regard been the worse, and a very big backward step in UNIX compatibility. 2 year after it came out, its shell still did not even understand most of the normal 'test' functions. A major pain to write shells scripts that need to also work on this system.

TheBonsai June 6, 2010, 12:35 pm

Yea, the question was if it's POSIX, not if it's 100% portable (which is a difference). The POSIX base more or less is a subset of the Korn features (88, 93), pure Bourne is something "else", I know. Real portability, which means a program can go wherever UNIX went, only in C ;)

Philippe Petrinko November 22, 2010, 8:23 am

And if you want to get rid of double-quotes, use:

one-liner code:
while read; do record=${REPLY}; echo ${record}|while read -d ","; do field="${REPLY#\"}"; field="${field%\"}"; echo ${field}; done; done<data

script code, added of some text to better see record and field breakdown:

#!/bin/bash
while read
do
echo "New record"
record=${REPLY}
echo ${record}|while read -d ,
do
field="${REPLY#\"}"
field="${field%\"}"
echo "Field is :${field}:"
done
done<data

Does it work with your data?

- PP

Philippe Petrinko November 22, 2010, 9:01 am

Of course, all the above code was assuming that your CSV file is named "data".

If you want to use anyname with the script, replace:

done<data

With:

done

And then use your script file (named for instance "myScript") with standard input redirection:

myScript < anyFileNameYouWant

Enjoy!

Philippe Petrinko November 22, 2010, 11:28 am

well no there is a bug, last field of each record is not read – it needs a workout and may be IFS modification ! After all that's what it was built for… :O)

Anthony Thyssen November 22, 2010, 11:31 pm

Another bug is the inner loop is a pipeline, so you can't assign variables for use later in the script. but you can use '<<<' to break the pipeline and avoid the echo.

But this does not help when you have commas within the quotes! Which is why you needed quotes in the first place.

In any case It is a little off topic. Perhaps a new thread for reading CVS files in shell should be created.

Philippe Petrinko November 24, 2010, 6:29 pm

Anthony,
Would you try this one-liner script on your CSV file?

This one-liner assumes that CSV file named [data] has __every__ field double-quoted.


while read; do r="${REPLY#\"}";echo "${r//\",\"/\"}"|while read -d \";do echo "Field is :${REPLY}:";done;done<data

Here is the same code, but for a script file, not a one-liner tweak.


#!/bin/bash
# script csv01.sh
#
# 1) Usage
# This script reads from standard input
# any CSV with double-quoted data fields
# and breaks down each field on standard output
#
# 2) Within each record (line), _every_ field MUST:
# - Be surrounded by double quotes,
# - and be separated from preceeding field by a comma
# (not the first field of course, no comma before the first field)
#
while read
do
echo "New record" # this is not mandatory-just for explanation
#
#
# store REPLY and remove opening double quote
record="${REPLY#\"}"
#
#
# replace every "," by a single double quote
record=${record//\",\"/\"}
#
#
echo ${record}|while read -d \"
do
# store REPLY into variable "field"
field="${REPLY}"
#
#
echo "Field is :${field}:" # just for explanation
done
done

This script named here [cvs01.sh] must be used so:

cvs01.sh < my-cvs-file-with-doublequotes

Philippe Petrinko November 24, 2010, 6:35 pm

@Anthony,

By the way, using [REPLY] in the outer loop _and_ the inner loop is not a bug.
As long as you know what you do, this is not problem, you just have to store [REPLY] value conveniently, as this script shows.

TheBonsai March 8, 2011, 6:26 am
for ((i=1; i<=20; i++)); do printf "%02d\n" "$i"; done

nixCraft March 8, 2011, 6:37 am

+1 for printf due to portability, but you can use bashy .. syntax too

for i in {01..20}; do echo "$i"; done

TheBonsai March 8, 2011, 6:48 am

Well, it isn't portable per se, it makes it portable to pre-4 Bash versions.

I think a more or less "portable" (in terms of POSIX, at least) code would be

i=0
while [ "$((i >= 20))" -eq 0 ]; do
  printf "%02d\n" "$i"
  i=$((i+1))
done

Philip Ratzsch April 20, 2011, 5:53 am

I didn't see this in the article or any of the comments so I thought I'd share. While this is a contrived example, I find that nesting two groups can help squeeze a two-liner (once for each range) into a one-liner:

for num in {{1..10},{15..20}};do echo $num;done

Great reference article!

Philippe Petrinko April 20, 2011, 8:23 am

@Philip
Nice thing to think of, using brace nesting, thanks for sharing.

Philippe Petrinko May 6, 2011, 10:13 am

Hello Sanya,

That would be because brace expansion does not support variables. I have to check this.
Anyway, Keep It Short and Simple: (KISS) here is a simple solution I already gave above:

xstart=1;xend=10;xstep=1
for (( x = $xstart; x <= $xend; x += $xstep)); do echo $x;done

Actually, POSIX compliance allows to forget $ in for quotes, as said before, you could also write:

xstart=1;xend=10;xstep=1
for (( x = xstart; x <= xend; x += xstep)); do echo $x;done

Philippe Petrinko May 6, 2011, 10:48 am

Sanya,

Actually brace expansion happens __before__ $ parameter exapansion, so you cannot use it this way.

Nevertheless, you could overcome this this way:

max=10; for i in $(eval echo {1..$max}); do echo $i; done

Sanya May 6, 2011, 11:42 am

Hello, Philippe

Thanks for your suggestions
You basically confirmed my findings, that bash constructions are not as simple as zsh ones.
But since I don't care about POSIX compliance, and want to keep my scripts "readable" for less experienced people, I would prefer to stick to zsh where my simple for-loop works

Cheers, Sanya

Philippe Petrinko May 6, 2011, 12:07 pm

Sanya,

First, you got it wrong: solutions I gave are not related to POSIX, I just pointed out that POSIX allows not to use $ in for (( )), which is just a little bit more readable – sort of.

Second, why do you see this less readable than your [zsh] [for loop]?

for (( x = start; x <= end; x += step)) do
echo "Loop number ${x}"
done

It is clear that it is a loop, loop increments and limits are clear.

IMNSHO, if anyone cannot read this right, he should not be allowed to code. :-D

BFN

Anthony Thyssen May 8, 2011, 11:30 pm

If you are going to do… $(eval echo {1..$max});
You may as well use "seq" or one of the many other forms.
See all the other comments on doing for loops.

Tom P May 19, 2011, 12:16 pm

I am trying to use the variable I set in the for line on to set another variable with a different extension. Couldn't get this to work and couldnt find it anywhere on the web… Can someone help.

Example:

FILE_TOKEN=`cat /tmp/All_Tokens.txt`
for token in $FILE_TOKEN
do
A1_$token=`grep $A1_token /file/path/file.txt | cut -d ":" -f2`

my goal is to take the values from the ALL Tokens file and set a new variable with A1_ infront of it… This tells be that A1_ is not a command…

[Feb 27, 2011] Bash-4.2 available for FTP - gnu.bash.bug Google Groups

New Features
============

This is the second revision to the fourth major release of bash.

This release fixes several outstanding bugs in bash-4.1 and introduces
several new features.

The most notable new features are \u and \U unicode character escapes
for the echo and printf builtins and $'...' quoting, a new mechanism
to declare variables with attributes in the global scope from a shell
function, and new word expansion features. There are also a number of
changes to accommodate recent Posix shell interpretations, changing the
bash posix-mode behavior to align with the newly-intepreted standard.

Read the file NEWS in the bash-4.2 distribution for a complete
description of the new features. A copy of the relevant portions
is included below.

Changes have been made to the Readline library being released at
the same time as bash-4.2, readline-6.2, so that Bash can be
linked against an already-installed Readline library rather than
the private version in lib/readline. Only readline-6.0 and later
versions are able to provide all of the symbols that bash-4.2
requires; earlier versions of the Readline library will not work
correctly.

A complete list of changes between bash-4.1 and bash-4.2 is
available in the file CHANGES; the complete list is too large to
include in this message.

Readline
========

Also available is a new release of the standalone Readline library,
version 6.2, with its own configuration scripts and Makefiles.
It can be retrieved with the URLs

and from the usual GNU mirror sites.

Diffs from readline-6.1 are not available.

The formatted Readline documentation is included in the readline
distribution tar file.

A separate announcement listing the changes in Readline is being
distributed.

As always, thanks for your help.

Chet

+========== NEWS ==========+
This is a terse description of the new features added to bash-4.2 since
the release of bash-4.1. As always, the manual page (doc/bash.1) is
the place to look for complete descriptions.

1. New Features in Bash

a. `exec -a foo' now sets $0 to `foo' in an executable shell script without a
leading #!.

b. Subshells begun to execute command substitutions or run shell functions or
builtins in subshells do not reset trap strings until a new trap is
specified. This allows $(trap) to display the caller's traps and the
trap strings to persist until a new trap is set.

c. `trap -p' will now show signals ignored at shell startup, though their
disposition still cannot be modified.

d. $'...', echo, and printf understand \uXXXX and \UXXXXXXXX escape sequences.

e. declare/typeset has a new `-g' option, which creates variables in the global scope even when run in a shell function.

f. test/[/[[ have a new -v variable unary operator, which returns success if `variable' has been set.

g. Posix parsing changes to allow `! time command' and multiple consecutive
instances of `!' (which toggle) and `time' (which have no cumulative
effect).

h. Posix change to allow `time' as a command by itself to print the elapsed user, system, and real times for the shell and its children.

j. $((...)) is always parsed as an arithmetic expansion first, instead of as a potential nested command substitution, as Posix requires.

k. A new FUNCNEST variable to allow the user to control the maximum shell
function nesting (recursive execution) level.

l. The mapfile builtin now supplies a third argument to the callback command:
the line about to be assigned to the supplied array index.

m. The printf builtin has a new %(fmt)T specifier, which allows time values
to use strftime-like formatting.

n. There is a new `compat41' shell option.

o. The cd builtin has a new Posix-mandated `-e' option.

p. Negative subscripts to indexed arrays, previously errors, now are treated as offsets from the maximum assigned index + 1.

q. Negative length specifications in the ${var:offset:length} expansion, previously errors, are now treated as offsets from the end of the variable.

r. Parsing change to allow `time -p --'.

s. Posix-mode parsing change to not recognize `time' as a keyword if the following token begins with a `-'. This means no more Posix-mode `time -p'. Posix interpretation 267.

t. There is a new `lastpipe' shell option that runs the last command of a pipeline in the current shell context. The lastpipe option has no effect if job control is enabled.

u. History expansion no longer expands the `$!' variable expansion.

v. Posix mode shells no longer exit if a variable assignment error occurs
with an assignment preceding a command that is not a special builtin.

w. Non-interactive mode shells exit if -u is enabled and an attempt is made
to use an unset variable with the % or # expansions, the `//', `^', or
`,' expansions, or the parameter length expansion.

x. Posix-mode shells use the argument passed to `.' as-is if a $PATH search
fails, effectively searching the current directory. Posix-2008 change.

2. New Features in Readline

a. The history library does not try to write the history filename in the
current directory if $HOME is unset. This closes a potential security
problem if the application does not specify a history filename.

b. New bindable variable `completion-display-width' to set the number of
columns used when displaying completions.

c. New bindable variable `completion-case-map' to cause case-insensitive
completion to treat `-' and `_' as identical.

d. There are new bindable vi-mode command names to avoid readline's case-
insensitive matching not allowing them to be bound separately.

e. New bindable variable `menu-complete-display-prefix' causes the menu
completion code to display the common prefix of the possible completions
before cycling through the list, instead of after.

Bash 3.2

a. Changed the parameter pattern replacement functions to not anchor the pattern at the beginning of the string if doing global replacement - that combination doesn't make any sense.

b. When running in `word expansion only' mode (--wordexp option), inhibit process substitution.

c. Loadable builtins now work on MacOS X 10.[34].

d. Shells running in posix mode no longer set $HOME, as POSIX requires.

e. The code that checks for binary files being executed as shell scripts now checks only for NUL rather than any non-printing character.

f. Quoting the string argument to the [[ command's =~ operator now forces string matching, as with the other pattern-matching operators.

2. New Features in Readline

a. Calling applications can now set the keyboard timeout to 0, allowing poll-like behavior.

b. The value of SYS_INPUTRC (configurable at compilation time) is now used as the default last-ditch startup file.

c. The history file reading functions now allow windows-like \r\n line terminators.

Bash 3.1

a. Bash now understands LC_TIME as a special variable so that time display
tracks the current locale.

b. BASH_ARGC, BASH_ARGV, BASH_SOURCE, and BASH_LINENO are no longer created as `invisible' variables and may not be unset.

c. In POSIX mode, if `xpg_echo' option is enabled, the `echo' builtin doesn't try to interpret any options at all, as POSIX requires.

d. The `bg' builtin now accepts multiple arguments, as POSIX seems to specify.

e. Fixed vi-mode word completion and glob expansion to perform tilde expansion.

f. The `**' mathematic exponentiation operator is now right-associative.

g. The `ulimit' builtin has new options: -i (max number of pending signals), -q (max size of POSIX message queues), and -x (max number of file locks).

h. A bare `%' once again expands to the current job when used as a job specifier.

i. The `+=' assignment operator (append to the value of a string or array) is now supported for assignment statements and arguments to built-in commands that accept assignment statements.

j. BASH_COMMAND now preserves its value when a DEBUG trap is executed.

k. The `gnu_errfmt' option is enabled automatically if the shell is running in an emacs terminal window.

l. New configuration option: --single-help-strings. Causes long help text to be written as a single string; intended to ease translation.

m. The COMP_WORDBREAKS variable now causes the list of word break characters to be emptied when the variable is unset.

n. An unquoted expansion of $* when $IFS is empty now causes the positional parameters to be concatenated if the expansion doesn't undergo word splitting.

o. Bash now inherits $_ from the environment if it appears there at startup.

p. New shell option: nocasematch. If non-zero, shell pattern matching ignores case when used by `case' and `[[' commands.

q. The printf builtin takes a new option: -v var. That causes the output to be placed into var instead of on stdout.

r. By default, the shell no longer reports processes dying from SIGPIPE.

s. Bash now sets the extern variable `environ' to the export environment it creates, so C library functions that call getenv() (and can't use the shell-provided replacement) get current values of environment variables.

t. A new configuration option, `--enable-strict-posix-default', which will build bash to be POSIX conforming by default.

u. If compiled for strict POSIX conformance, LINES and COLUMNS may now override the true terminal size.

2. New Features in Readline

a. The key sequence sent by the keypad `delete' key is now automatically bound to delete-char.

b. A negative argument to menu-complete now cycles backward through the completion list.

c. A new bindable readline variable: bind-tty-special-chars. If non-zero, readline will bind the terminal special characters to their readline equivalents when it's called (on by default).

d. New bindable command: vi-rubout. Saves deleted text for possible reinsertion, as with any vi-mode `text modification' command; `X' is bound to this in vi command mode.

e. A new external application-controllable variable that allows the LINES and COLUMNS environment variables to set the window size regardless of what the kernel returns: rl_prefer_env_winsize

[Nov 5, 2004] Bash 3.0

This is a terse description of the new features added to bash-3.0 since the release of bash-2.05b. As always, the manual page (doc/bash.1) is the place to look for complete descriptions.

cc. The [[ ... ]] command has a new binary `=~' operator that performs extended regular expression (egrep-like) matching.

l. New invocation option: --debugger. Enables debugging and turns on new `extdebug' shell option.

f. HISTCONTROL may now include the `erasedups' option, which causes all lines matching a line being added to be removed from the history list.

j. for, case, select, arithmetic commands now keep line number information for the debugger.

p. `declare -F' now prints out extra line number and source file information if the `extdebug' option is set.

r. New `caller' builtin to provide a call stack for the bash debugger.

t. `for', `select', and `case' command heads are printed when `set -x' is enabled.

u. There is a new {x..y} brace expansion, which is shorthand for {x.x+1, x+2,...,y}. x and y can be integers or single characters; the sequence may ascend or descend; the increment is always 1.

v. New ksh93-like ${!array[@]} expansion, expands to all the keys (indices) of array.

z. New `-o plusdirs' option to complete and compgen; if set, causes directory name completion to be performed and the results added to the rest of the possible completions.

ee. Subexpressions matched by the =~ operator are placed in the new BASH_REMATCH array variable.

gg. New `set -o pipefail' option that causes a pipeline to return a failure status if any of the processes in the pipeline fail, not just the last one.

kk. The `\W' prompt expansion now abbreviates $HOME as `~', like `\w'.

ll. The error message printed when bash cannot open a shell script supplied as argument 1 now includes the name of the shell, to better identify the error as coming from bash.

2. New Features in Readline

a. History expansion has a new `a' modifier equivalent to the `g' modifier for compatibility with the BSD csh.

b. History expansion has a new `G' modifier equivalent to the BSD csh `g' modifier, which performs a substitution once per word.

c. All non-incremental search operations may now undo the operation of replacing the current line with the history line.

d. The text inserted by an `a' command in vi mode can be reinserted with `.'.

e. New bindable variable, `show-all-if-unmodified'. If set, the readline completer will list possible completions immediately if there is more than one completion and partial completion cannot be performed.

g. History list entries now contain timestamp information; the history file functions know how to read and write timestamp information associated with each entry.

n. When listing completions, directories have a `/' appended if the `mark-directories' option has been enabled.

Bash 2.05b

[Nov 1, 2002] bash-2.05b.tar.gz is now available. NEWS

d. `select' was changed to be more ksh-compatible, in that the menu is reprinted each time through the loop only if REPLY is set to NULL. The previous behavior is available as a compile-time option.

e. `complete -d' and `complete -o dirnames' now force a slash to be appended to names which are symlinks to directories.

g. Added support for ksh93-like [:word:] character class in pattern matching.

h. The $'...' quoting construct now expands \cX to Control-X.

i. A new \D{...} prompt expansion; passes the `...' to strftime and inserts the result into the expanded prompt.

j. The shell now performs arithmetic in the largest integer size the machine supports (intmax_t), instead of long.

k. If a numeric argument is supplied to one of the bash globbing completion functions, a `*' is appended to the word before expansion is attempted.

l. The bash globbing completion functions now allow completions to be listed with double tabs or if `show-all-if-ambiguous' is set.

m. New `-o nospace' option for `complete' and `compgen' builtins; suppresses readline's appending a space to the completed word.

n. New `here-string' redirection operator: <<< word.

o. When displaying variables, function attributes and definitions are shown separately, allowing them to be re-used as input (attempting to re-use the old output would result in syntax errors).

r. `read' has a new `-u fd' option to read from a specified file descriptor.

u. The `printf' %q format specifier now uses $'...' quoting to print the argument if it contains non-printing characters.

v. The `declare' and `typeset' builtins have a new `-t' option. When applied to functions, it causes the DEBUG trap to be inherited by the named function. Currently has no effect on variables.

w. The DEBUG trap is now run *before* simple commands, ((...)) commands, [[...]] conditional commands, and for ((...)) loops.

z. New [n]<&word- and [n]>&word- redirections from ksh93 -- move fds (dup
and close).

bb. The `hash' builtin has a new `-l' option to list contents in a reusable format, and a `-d' option to remove a name from the hash table.

dd. All builtins that take operands accept a `--' pseudo-option, except `echo'.

2. New Features in Readline

a. Support for key `subsequences': allows, e.g., ESC and ESC-a to both be bound to readline functions. Now the arrow keys may be used in vi insert mode.

h. Readline now has an overwrite mode, toggled by the `overwrite-mode' bindable command, which could be bound to `Insert'.

i. New application-settable completion variable: rl_completion_suppress_append, inhibits appending of rl_completion_append_character to completed words.

j. New key bindings when reading an incremental search string: ^W yanks the currently-matched word out of the current line into the search string; ^Y yanks the rest of the current line into the search string, DEL or ^H deletes characters from the search string.

Bash 2.05a


This is a terse description of the new features added to bash-2.05a since the release of bash-2.05. As always, the manual page (doc/bash.1) is the place to look for complete descriptions.

g. New `\A' prompt string escape sequence; expands to time in 24 HH:MM format.

h. New `-A group/-g' option to complete and compgen; does group name completion.

i. New `-t' option to `hash' to list hash values for each filename argument.

j. New [-+]O invocation option to set and unset `shopt' options at startup.

l. The ksh-like `ERR' trap has been added. The `ERR' trap will be run whenever the shell would have exited if the -e option were enabled. It is not inherited by shell functions.

m. `readonly', `export', and `declare' now print variables which have been given attributes but not set by assigning a value as just a command and a variable name (like `export foo') when listing, as the latest POSIX drafts require.

p. `for' loops now allow empty word lists after `in', like the latest POSIX drafts require.

q. The builtin `ulimit' now takes two new non-numeric arguments: `hard', meaning the current hard limit, and `soft', meaning the current soft limit, in addition to `unlimited'

r. `ulimit' now prints the option letter associated with a particular resource when printing more than one limit.

s. `ulimit' prints `hard' or `soft' when a value is not `unlimited' but is one of RLIM_SAVED_MAX or RLIM_SAVED_CUR, respectively.

t. The `printf' builtin now handles the %a and %A conversions if they're implemented by printf(3).

u. The `printf' builtin now handles the %F conversion (just about like %f).

v. The `printf' builtin now handles the %n conversion like printf(3). The corresponding argument is the name of a shell variable to which the value is assigned.

2. New Features in Readline

a. Added extern declaration for rl_get_termcap to readline.h, making it a public function (it was always there, just not in readline.h).

b. New #defines in readline.h: RL_READLINE_VERSION, currently 0x0402,
RL_VERSION_MAJOR, currently 4, and RL_VERSION_MINOR, currently 2.

c. New readline variable: rl_readline_version, mirrors RL_READLINE_VERSION.

d. New bindable boolean readline variable: match-hidden-files. Controls completion of files beginning with a `.' (on Unix). Enabled by default.

e. The history expansion code now allows any character to terminate a `:first-' modifier, like csh.

f. New bindable variable `history-preserve-point'. If set, the history code attempts to place the user at the same location on each history line retrived with previous-history or next-history.

Bash 2.05

a. Added a new `--init-file' invocation argument as a synonym for `--rcfile',
per the new GNU coding standards.

b. The /dev/tcp and /dev/udp redirections now accept service names as well as
port numbers.

c. `complete' and `compgen' now take a `-o value' option, which controls some
of the aspects of that compspec. Valid values are:

default - perform bash default completion if programmable
completion produces no matches
dirnames - perform directory name completion if programmable
completion produces no matches
filenames - tell readline that the compspec produces filenames,
so it can do things like append slashes to
directory names and suppress trailing spaces

d. A new loadable builtin, realpath, which canonicalizes and expands symlinks
in pathname arguments.

e. When `set' is called without options, it prints function defintions in a
way that allows them to be reused as input. This affects `declare' and
`declare -p' as well. This only happens when the shell is not in POSIX
mode, since POSIX.2 forbids this behavior.

f. Bash-2.05 once again honors the current locale setting when processing
ranges within pattern matching bracket expressions (e.g., [A-Z]).

2. New Features in Readline

a. The blink timeout for paren matching is now settable by applications,
via the rl_set_paren_blink_timeout() function.

b. _rl_executing_macro has been renamed to rl_executing_macro, which means
it's now part of the public interface.

c. Readline has a new variable, rl_readline_state, which is a bitmap that
encapsulates the current state of the library; intended for use by
callbacks and hook functions.

d. New application-callable function rl_set_prompt(const char *prompt):
expands its prompt string argument and sets rl_prompt to the result.

e. New application-callable function rl_set_screen_size(int rows, int cols):
public method for applications to set readline's idea of the screen
dimensions.

f. New function, rl_get_screen_size (int *rows, int *columns), returns
readline's idea of the screen dimensions.

g. The timeout in rl_gather_tyi (readline keyboard input polling function)
is now settable via a function (rl_set_keyboard_input_timeout()).

h. Renamed the max_input_history variable to history_max_entries; the old
variable is maintained for backwards compatibility.

i. The list of characters that separate words for the history tokenizer is
now settable with a variable: history_word_delimiters. The default
value is as before.

Bash 2.04

a. The history builtin has a `-d offset' option to delete the history entry
at position `offset'.

b. The prompt expansion code has two new escape sequences: \j, the number of
active jobs; and \l, the basename of the shell's tty device name.

c. The `bind' builtin has a new `-x' option to bind key sequences to shell
commands.

d. There is a new shell option, no_empty_command_completion, which, when
enabled, disables command completion when TAB is typed on an empty line.

e. The `help' builtin has a `-s' option to just print a builtin's usage
synopsis.

f. There are several new arithmetic operators: id++, id-- (variable
post-increment/decrement), ++id, --id (variable pre-increment/decrement),
expr1 , expr2 (comma operator).

g. There is a new ksh-93 style arithmetic for command:
for ((expr1 ; expr2; expr3 )); do list; done

h. The `read' builtin has a number of new options:
-t timeout only wait timeout seconds for input
-n nchars only read nchars from input instead of a full line
-d delim read until delim rather than newline
-s don't echo input chars as they are read

i. The redirection code now handles several filenames specially:
/dev/fd/N, /dev/stdin, /dev/stdout, and /dev/stderr, whether or
not they are present in the file system.

j. The redirection code now recognizes pathnames of the form
/dev/tcp/host/port and /dev/udp/host/port, and tries to open a socket
of the appropriate type to the specified port on the specified host.

k. The ksh-93 ${!prefix*} expansion, which expands to the names of all
shell variables with prefix PREFIX, has been implemented.

l. There is a new dynamic variable, FUNCNAME, which expands to the name of
a currently-executing function. Assignments to FUNCNAME have no effect.

m. The GROUPS variable is no longer readonly; assignments to it are silently
discarded. This means it can be unset.

n. A new programmable completion facility, with two new builtin commands:
complete and compgen.

o. configure has a new option, `--enable-progcomp', to compile in the
programmable completion features (enabled by default).

p. `shopt' has a new option, `progcomp', to enable and disable programmable
completion at runtime.

q. Unsetting HOSTFILE now clears the list of hostnames used for completion.

r. configure has a new option, `--enable-bash-malloc', replacing the old
`--with-gnu-malloc' (which is still present for backwards compatibility).

s. There is a new manual page describing rbash, the restricted shell.

t. `bashbug' has new `--help' and `--version' options.

u. `shopt' has a new `xpg_echo' option, which controls the behavior of
`echo' with respect to backslash-escaped characters at runtime.

v. If NON_INTERACTIVE_LOGIN_SHELLS is defined, all login shells read the
startup files, even if they are not interactive.

w. The LC_NUMERIC variable is now treated specially, and used to set the
LC_NUMERIC locale category for number formatting, e.g., when `printf'
displays floating-point numbers.

2. New features in Readline

a. Parentheses matching is now always compiled into readline, and enabled
or disabled when the value of the `blink-matching-paren' variable is
changed.

b. MS-DOS systems now use ~/_inputrc as the last-ditch inputrc filename.

c. MS-DOS systems now use ~/_history as the default history file.

d. history-search-{forward,backward} now leave the point at the end of the
line when the string to search for is empty, like
{reverse,forward}-search-history.

e. history-search-{forward,backward} now leave the last history line found
in the readline buffer if the second or subsequent search fails.

f. New function for use by applications: rl_on_new_line_with_prompt, used
when an application displays the prompt itself before calling readline().

g. New variable for use by applications: rl_already_prompted. An application
that displays the prompt itself before calling readline() must set this to
a non-zero value.

h. A new variable, rl_gnu_readline_p, always 1. The intent is that an
application can verify whether or not it is linked with the `real'
readline library or some substitute.

Bash 2.03

a. New `shopt' option, `restricted_shell', indicating whether or not the
shell was started in restricted mode, for use in startup files.

b. Filename generation is now performed on the words between ( and ) in
array assignments (which it probably should have done all along).

c. OLDPWD is now auto-exported, as POSIX.2 seems to require.

d. ENV and BASH_ENV are read-only variables in a restricted shell.

e. A change was made to the startup file code so that any shell begun with
the `--login' option, even non-interactive shells, will source the login
shell startup files.

2. New Features in Readline

a. Many changes to the signal handling:
o Readline now catches SIGQUIT and cleans up the tty before returning;
o A new variable, rl_catch_signals, is available to application writers
to indicate to readline whether or not it should install its own
signal handlers for SIGINT, SIGTERM, SIGQUIT, SIGALRM, SIGTSTP,
SIGTTIN, and SIGTTOU;
o A new variable, rl_catch_sigwinch, is available to application
writers to indicate to readline whether or not it should install its
own signal handler for SIGWINCH, which will chain to the calling
applications's SIGWINCH handler, if one is installed;
o There is a new function, rl_free_line_state, for application signal
handlers to call to free up the state associated with the current
line after receiving a signal;
o There is a new function, rl_cleanup_after_signal, to clean up the
display and terminal state after receiving a signal;
o There is a new function, rl_reset_after_signal, to reinitialize the
terminal and display state after an application signal handler
returns and readline continues

b. There is a new function, rl_resize_terminal, to reset readline's idea of
the screen size after a SIGWINCH.

c. New public functions: rl_save_prompt and rl_restore_prompt. These were
previously private functions with a `_' prefix.

d. New function hook: rl_pre_input_hook, called just before readline starts
reading input, after initialization.

e. New function hook: rl_display_matches_hook, called when readline would
display the list of completion matches. The new function
rl_display_match_list is what readline uses internally, and is available
for use by application functions called via this hook.

f. New bindable function, delete-char-or-list, like tcsh.

g. A new variable, rl_erase_empty_line, which, if set by an application using
readline, will cause readline to erase, prompt and all, lines on which the
only thing typed was a newline.

h. New bindable variable: `isearch-terminators'.

i. New bindable function: `forward-backward-delete-char' (unbound by default).

Bash 2.02

a. A new version of malloc, based on the older GNU malloc, that has many changes, is more page-based, is more conservative with memory usage, and does not `orphan' large blocks when they are freed.

b. A new version of gmalloc, based on the old GLIBC malloc, with many changes and range checking included by default.

c. A new implementation of fnmatch(3) that includes full POSIX.2 Basic Regular Expression matching, including character classes, collating symbols, equivalence classes, and support for case-insensitive pattern matching.

d. ksh-88 egrep-style extended pattern matching ([@+*?!](patlist)) has been implemented, controlled by a new `shopt' option, `extglob'.

e. There is a new ksh-like `[[' compound command, which implements extended `test' functionality.

f. There is a new `printf' builtin, implemented according to the POSIX.2 specification.

g. There is a new feature for command substitution: $(< filename) now expands to the contents of `filename', with any trailing newlines removed (equivalent to $(cat filename)).

h. There are new tilde prefixes which expand to directories from the directory stack.

i. There is a new `**' arithmetic operator to do exponentiation.

j. There are new configuration options to control how bash is linked: `--enable-profiling', to allow bash to be profiled with gprof, and `--enable-static-link', to allow bash to be linked statically.

k. There is a new configuration option, `--enable-cond-command', which controls whether or not the `[[' command is included. It is on by default.

l. There is a new configuration option, `--enable-extended-glob', which controls whether or not the ksh extended globbing feature is included. It is enabled by default.

m. There is a new configuration #define in config.h.top that, when enabled, will cause all login shells to source /etc/profile and one of the user-specific login shell startup files, whether or not the shell is interactive.

n. There is a new invocation option, `--dump-po-strings', to dump a shell script's translatable strings ($"...") in GNU `po' format.

o. There is a new `shopt' option, `nocaseglob', to enable case-insensitive pattern matching when globbing filenames and using the `case' construct.

p. There is a new `shopt' option, `huponexit', which, when enabled, causes the shell to send SIGHUP to all jobs when an interactive login shell exits.

q. `bind' has a new `-u' option, which takes a readline function name as an argument and unbinds all key sequences bound to that function in a specified keymap.

r. `disown' now has `-a' and `-r' options, to limit operation to all jobs and running jobs, respectively.

s. The `shopt' `-p' option now causes output to be displayed in a reusable format.

t. `test' has a new `-N' option, which returns true if the filename argument has been modified since it was last accessed.

u. `umask' now has a `-p' option to print output in a reusable format.

v. A new escape sequence, `\xNNN', has been added to the `echo -e' and $'...' translation code. It expands to the character whose ascii code is NNN in hexadecimal.

w. The prompt string expansion code has a new `\r' escape sequence.

x. The shell may now be cross-compiled for the CYGWIN32 environment on a Unix machine.

2. New Features in Readline

a. There is now an option for `iterative' yank-last-arg handline, so a user can keep entering `M-.', yanking the last argument of successive history lines.

b. New variable, `print-completions-horizontally', which causes completion matches to be displayed across the screen (like `ls -x') rather than up and down the screen (like `ls').

c. New variable, `completion-ignore-case', which causes filename completion and matching to be performed case-insensitively.

d. There is a new bindable command, `magic-space', which causes history expansion to be performed on the current readline buffer and a space to be inserted into the result.

e. There is a new bindable command, `menu-complete', which enables tcsh-like menu completion (successive executions of menu-complete insert a single completion match, cycling through the list of possible completions).

f. There is a new bindable command, `paste-from-clipboard', for use on Win32 systems, to insert the text from the Win32 clipboard into the editing buffer.

g. The key sequence translation code now understands printf-style backslash escape sequences, including \NNN octal escapes. These escape sequences may be used in key sequence definitions or macro values.

h. An `$include' inputrc file parser directive has been added.

Bash 2.01

This is a terse description of the new features added to bash-2.01 since the release of bash-2.0. As always, the manual page (doc/bash.1) is the place to look for complete descriptions.

1. New Features in Bash

a. There is a new builtin array variable: GROUPS, the set of groups to which the user belongs. This is used by the test suite.

2. New Features in Readline

a. If a key sequence bound to `universal-argument' is read while reading a numeric argument started with `universal-argument', it terminates the argument but is otherwise ignored. This provides a way to insert multiple instances of a digit string, and is how GNU emacs does it.

-------------------------------------------------------------------------------
This is a terse description of the new features added to bash-2.0 since the release of bash-1.14.7. As always, the manual page (doc/bash.1) is the place to look for complete descriptions.

1. New Features in Bash

a. There is a new invocation option, -D, that dumps translatable strings in a script.

b. The `long' invocation options must now be prefixed with `--'.

c. New long invocation options: --dump-strings, --help, --verbose

d. The `nolineediting' invocation option was renamed to `noediting'.

e. The `nobraceexpansion' and `quiet' long invocation options were removed.

f. The `--help' and `--version' long options now work as the GNU coding standards specify.

g. If invoked as `sh', bash now enters posix mode after reading the startup files, and reads and executes commands from the file named by $ENV if interactive (as POSIX.2 specifies). A login shell invoked as `sh' reads $ENV after /etc/profile and ~/.profile.

h. There is a new reserved word, `time', for timing pipelines, builtin commands, and shell functions. It uses the value of the TIMEFORMAT variable as a format string describing how to print the timing statistics.

i. The $'...' quoting syntax expands ANSI-C escapes in ... and leaves the result single-quoted.

j. The $"..." quoting syntax performs locale-specific translation of ... and leaves the result double-quoted.

k. LINENO now works correctly in functions.

l. New variables: DIRSTACK, PIPESTATUS, BASH_VERSINFO, HOSTNAME, SHELLOPTS, MACHTYPE. The first three are array variables.

m. The BASH_VERSION and BASH_VERSINFO variables now include the shell's `release status' (alpha[N], beta[N], release).

n. Some variables have been removed: MAIL_WARNING, notify, history_control, command_oriented_history, glob_dot_filenames, allow_null_glob_expansion, nolinks, hostname_completion_file, noclobber, no_exit_on_failed_exec, and cdable_vars. Most of them are now implemented with the new `shopt' builtin; others were already implemented by `set'.

o. Bash now uses some new variables: LC_ALL, LC_MESSAGES, LC_CTYPE, LC_COLLATE, LANG, GLOBIGNORE, HISTIGNORE.

p. The shell now supports integer-indexed arrays of unlimited length, with a new compound assignment syntax and changes to the appropriate builtin commands (declare/typeset, read, readonly, etc.). The array index may be an arithmetic expression.

q. ${!var}: indirect variable expansion, equivalent to eval \${$var}.

r. ${paramter:offset[:length]}: variable substring extraction.

s. ${parameter/pattern[/[/]string]}: variable pattern substitution.

t. The $[...] arithmetic expansion syntax is no longer supported, in favor of $((...)).

u. Aliases can now be expanded in shell scripts with a shell option (shopt expand_aliases).

v. History and history expansion can now be used in scripts with set -o history and set -H.

w. All builtins now return an exit status of 2 for incorrect usage.

x. Interactive shells resend SIGHUP to all running or stopped children if (and only if) they exit due to a SIGHUP.

y. New prompting expansions: \a, \e, \H, \T, \@, \v, \V.

z. Variable expansion in prompt strings is now controllable via a shell option (shopt promptvars).

aa. Bash now defaults to using command-oriented history.

bb. The history file ($HISTFILE) is now truncated to $HISTFILESIZE after being written.

cc. The POSIX.2 conditional arithmetic evaluation syntax (expr ? expr : expr) has been implemented.

dd. Each builtin now accepts `--' to signify the end of the options, except as documented (echo, etc.).

ee. All builtins use -p to display values in a re-readable format where appropriate, except as documented (echo, type, etc.).

ff. The `alias' builtin has a new -p option.

gg. Changes to the `bind' builtin:

hh. The `bye' synonym for `exit' was removed.

ii. The -L and -P options to `cd' and `pwd' have been documented.

jj. The `cd' builtin now does spelling correction on the directory name by default. This is settable with a shell option (shopt cdspell).

kk. The `declare' builtin has new options: -a, -F, -p.

ll. The `dirs' builtin has new options: -c, -p, -v.

mm. The new `disown' builtin removes jobs from the shell's jobs table or inhibits the resending of SIGHUP when the shell receives a SIGHUP.

nn. The `echo' builtin has a new escape character: \e.

oo. The `enable' builtin can now load new builtins dynamically from shared objects on systems with the dlopen/dlsym interface. There are a number of examples in the examples/loadables directory. There are also new options: -d, -f, -s, -p.

pp. The `-all' option to `enable' was removed in favor of `-a'.

qq. The `exec' builtin has new options: -l, -c, -a.

rr. The `hash' builtin has a new option: -p.

ss. The `history' builtin has new options: -c, -p, -s.

tt. The `jobs' builtin has new options: -r, -s.

uu. The `kill' builtin has new options: -n signum, -l signame.

vv. The `pushd' and `popd' builtins have a new option: -n.

ww. The `read' builtin has new options: -p prompt, -e, -a.

xx. The `readonly' builtin has a new -a option, and the -n option was removed.

yy. Changes to the `set' builtin:
o new options: -B, -o keyword, -o onecmd, -o history
o options removed: -l, -d, -o nohash
o options changed: +o, -h, -o hashall
o now displays variables in a format that can be re-read as input

zz. The new `shopt' builtin controls shell optional behavior previously
done by setting and unsetting certain shell variables.

aaa. The `test' builtin has new operators: -o option, s1 == s2, s1 < s2,
and s1 > s2, where s1 and s2 are strings.

bbb. There is a new trap, DEBUG, executed after every simple command.

ccc. The `trap' builtin has a new -p option.

ddd. The `ulimit' builtin has a new -l option on 4.4BSD-based systems.

eee. The PS1, PS2, PATH, and IFS variables may now be unset.

fff. The restricted shell mode has been expanded and is now documented.

ggg. Security improvements:
o functions are not imported from the environment if running setuid or with -p
o no startup files are sourced if running setuid or with -p

hhh. The documentation has been overhauled: the texinfo manual was expanded, and HTML versions of the man page and texinfo manual are included.

iii. Changes to Posix mode:
o Command lookup now finds special builtins before shell functions.
o Failure of a special builtin causes a non-interactive shell to
exit. Failures are defined in the POSIX.2 specification.
o If the `cd' builtin finds a directory to change to using $CDPATH,
the value assigned to PWD when `cd' completes does not contain
any symbolic links.
o A non-interactive shell exits if a variable assignment error
occurs when no command name follows the assignment statements.
o A non-interactive shell exits if the interation variable in a
`for' statement or the selection variable in a `select' statement
is read-only or another variable assignment error occurs.
o The `<>' redirection operator now opens a file for both stdin and stdout by default, not just when in posix mode.
o Assignment statements preceding special builtins now persist in the shell's environment when the builtin completes.

Posix mode is now completely POSIX.2-compliant (modulo bugs). When invoked as sh, bash should be completely POSIX.2-compliant.

jjj. The default value of PS1 is now "\s-\v\$ ".

kkk. The ksh-like ((...)) arithmetic command syntax has been implemented. This is exactly equivalent to `let "..."'.

lll. Integer constants have been extended to base 64.

mmm. The `ulimit' builtin now sets both hard and soft limits and reports the soft limit by default.

2. New Features in Readline

a. New variables: enable-keypad, input-meta (new name for meta-flag), mark-directories, visible-stats (now documented), disable-completion, comment-begin.

b. New bindable commands: kill-region, copy-region-as-kill, copy-backward-word, copy-forward-word, set-mark, exchange-point-and-mark, character-search, character-search-backward, insert-comment, glob-expand-word, glob-list-expansions, dump-variables, dump-macros.

c. New emacs keybindings: delete-horizontal-space (M-\), insert-completions (M-*), possible-completions (M-=).

d. The history-search-backward and history-search-forward commands were
modified to be the same as previous-line and next-line if point is at
the start of the line.

e. More file types are available for the visible-stats mode.

3. Changes of interest in the Bash implementation

a. There is a new autoconf-based configuration mechanism.

b. More things have been moved from Posix mode to standard shell behavior.

c. The trace output (set -x) now inserts quotes where necessary so it can
be reused as input.

d. There is a compile-time option for a system-wide interactive shell
startup file (disabled by default).

e. The YACC grammar is smaller and tighter, and all 66 shift-reduce
conflicts are gone. Several parsing bugs have been fixed.

f. Builtin option parsing has been regularized (using internal_getopt()),
with the exception of `echo', `type', and `set'.

g. Builtins now return standard usage messages constructed from the
`short doc' used by the help builtin.

h. Completion now quotes using backslashes by default, but honors
user-supplied quotes.

i. The GNU libc malloc is available as a configure-time option.

j. There are more internationalization features; bash uses gettext if
it is available. The $"..." translation syntax uses the current
locale and gettext.

k. There is better reporting of job termination when the shell is not
interactive.

l. The shell is somewhat more efficient: it uses a little less memory and
makes fewer system calls.

4. Changes of interest in the Readline implementation

a. There is now support for readline `callback' functions.

b. There is now support for user-supplied input, redisplay, and terminal
preparation functions.

c. Most of the shell-specific code in readline has been generalized or
removed.

d. Most of the annoying redisplay bugs have been fixed, notably the problems
with incremental search and excessive redrawing when special characters
appear in the prompt string.

e. There are new library functions and variables available to application
writers, most having to do with completion and quoting.

f. The NEWLINE character (^J) is now treated as a search terminator by the
incremental search functions.

Major Differences From The Bourne Shell

Bash implements essentially the same grammar, parameter and variable expansion, redirection, and quoting as the Bourne Shell. Bash uses the POSIX 1003.2 standard as the specification of how these features are to be implemented. There are some differences between the traditional Bourne shell and Bash; this section quickly details the differences of significance. A number of these differences are explained in greater depth in previous sections. This section uses the version of sh included in SVR4.2 as the baseline reference.

More features unique to Bash may be found in section 6 Bash Features.

B.1 Implementation Differences From The SVR4.2 Shell

Since Bash is a completely new implementation, it does not suffer from many of the limitations of the SVR4.2 shell. For instance:



Etc

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to to buy a cup of coffee for authors of this site

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: April, 23, 2019