|
Softpanorama |
May the source be with you, but remember the KISS principle ;-)
|
[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.
-------------------------------------------------------------------------------
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.
[Sept 17, 2002] BASH with Debugger and Improved Debug Support and Error Handling
The Bash Debugger Project contains patched sources to BASH that enable better debugging support as well as improved error reporting. In addition, this project contains the most comprehensive source-code debugger for bash that has been written.
Since this project maintains as an open CVS development and encourages developers and ideas, the space could be also be used springboard for other experiments and additions to BASH. If you are interesting in contributing to this project, please contact rocky@panix.com.
However, if you are looking for the plain vanilla BASH, try here.
| Documentation | On-line documentation. |
|---|---|
| Download | Get the latest version here. |
| CVS | Browse the CVS Tree |
| Sourceforge | The
sourceforge.net project page.
|
[Jul 18, 2002] The GNU Bourne-Again Shell bash 2.05 is now available; most important NEWS:
GNU shtool 1.6.1 Ralf S. Engelschall Saturday, July 13th 2002 15:28 EDT
About: GNU shtool is a compilation of small but very stable and portable shell scripts into a single shell tool. All ingredients were in successful use over many years in various free software projects. The compiled shtool program is intended to be used inside the source tree of free software packages. There it can overtake various (usually non-portable) tasks related to the building and installation of an free software package.
Changes: The non-existent --min-size option was removed from the usage of "shtool rotate". The following was ported to the POSIX 1003.1-2001 (SUSv3) standard: sh.echo, sh.version, sh.path, sh.subst. Various typos in shtool.pod were fixed.
Version Focus Date 1.6.1 Minor bugfixes 13-Jul-2002 15:28
5 Bash tips every Linux user should know - Aug 22, 2001
history|grep -i first few letters of command
This will read the history file (located in
~/.history) and perform a case insensitive search on the command you are looking for. Here is example output from my machine: [jd@jd bash]$ history|grep -i POSTGRES
29 cvs update -d postgres
30 cd postgres/
61 cd projects/postgres/
I now have a list of commands
that match my requirements. If the command is in the list, I can use the
! key to execute one
of the commands. If I wanted to execute
dvips -f practicalpostgresql.dvi -o practicalpostgresql.ps,
for example, I could just type
!73 which is the
corresponding history number with the command I want to execute. The second
method of finding the command you are looking for is to use history
completion, which is discussed next.
ctrl-r and then
begin typing the command. You will notice ctrl-r finishes the command for you
as you type. If you can remember to use
ctrl-r, it
will become invaluable for repeating longer commands.
cd /usr/local/ but I
don't quite remember the name of the next directory in the path I can use the
tab key to have Bash auto-complete the name. If there are multiple
directories or file available, Bash will beep to indicate that there is not a
clear option to complete. It will then display a listing of the available
options if you press tab again. Here is example output when using tab
completion to enter a directory in
[jd@jd bash]$ cd /usr/local/
HancomOffice Loki_Update bin
etc
info
man
prod soffice
Loki_Uninstall appgen doc
games lib
mozilla sbin src
jade -E 200 -t sgml -V html-index -d /usr/lib/sgml/stylesheets/nwalsh-modular/html/docbook.dsl practicalpostgresql.sgml
This would be difficult and tiresome to type over and over as you are writing and processing a document. Instead, you can use the
alias bash command.
Using the above example we can use the
alias command like
this:
alias pghtml='jade -E 200 -t sgml -V html-index -d /usr/lib/sgml/stylesheets/nwalsh-modular/html/docbook.dsl practicalpostgresql.sgml'
Now, if you type just
pghtml at the
command line, it will process the aliased jade command. Place this in your
.bash_profile, or
else it will not be stored in memory the next time you log in. You can have
any amount of aliases that you desire, though they must, of course, have
unique names. On my system the output looks like this:
[jd@jd practicalpostgresql]$ alias
alias l='ls'
alias la='ls -A -k'
alias ll='ls -l'
alias ls='ls -F --color=auto'
alias lsd='ls -d */'
alias md='mkdir'
alias p='cd -'
[May 17, 2002] Since v2.04, bash has allowed to intelligently program and extend its standard completion behavior to achieve complex command lines with just a few keystrokes.
Imagine typing ssh [Tab] and being able to complete on hosts from your ~/.ssh/known_hosts files. Or typing man 3 str [Tab] and getting a list of all string handling functions in the UNIX manual. mount system: [Tab] would complete on all exported file-systems from the host called system, while make [Tab] would complete on all targets in Makefile.
[Mar 25, 2002] UnixReview.com/Shell corner -- some potentially useful scripts.
[Mar 10, 2002] Unix pipes -- examples of scripts that use pipes. Most examples are pretty trivial.
GNU shtool - GNU Project - Free Software Foundation (FSF) Several useful scripts (bash):
echo(1)
style print command providing special expansion constructs (terminal bold
mode, environment details, date) and newline control. mv(1)
style command, but can rename/move multiple files at once and allows source
files just to be deleted if contents didn't change.
mkdir(1)
style command providing support for auto-parent-dir creation, directory
permission control and smart skipping if directory already exists.
-- ln(1) style command providing
automatic calculation and usage of relative links if possible. sed(1) substitution
operations to multiple files
cpp(1) code, internal
variables and internal functions.
In a recent thread on
comp.unix.shell, the following example was posted by Andreas Schwab as another Useful Use of Cat on a lone file:{ foo; bar; cat mumble; baz } | whateverHere, the contents of the file
mumbleare output to stdout after the output from the programsfooandbar, and before the output ofbaz. All the generated output is piped to the programwhatever. (Read up on shell programming constructs if this was news to you:-)
Advanced Bash-Scripting Guide Revision 1.1, 06 January 2002 Daniel Robbins' three-part series on bash programming on developerWorks: Part 1, Part 2, and Part 3.
ksh93 rpms:
**** Example of ksh profile that contains interesting but probably non-optimal way to distinguish between interactive and non-intractive shells [Feb 2, 2002]
ENV='$\{FILE[(\_\$-=0)+(\_=1)-\_\$\{-\%\%*i*\}]\}'
export ENV
Advanced Bash-Scripting Guide -- by Mendel Cooper [06 Jan, 2002[
Revision 1.1 06 January 2002 Revised by: mc Bugfixes, material and scripts added. This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward an intermediate/advanced level of instruction (...all the while sneaking in little snippets of UNIX wisdom and lore). It serves as a textbook, a manual for self-study, and a reference and source of knowledge on shell scripting techniques. The exercises and heavily-commented examples invite active reader participation, under the premise that the only way to really learn scripting is to write scripts.
The latest update of this document, as an archived "tarball" including both the SGML source and rendered HTML, may be downloaded from the author's home site. See the change log for a revision history.
developerWorks Linux Using Bash shell scripts for function testing
"Function testing is the phase during a development cycle in which the software application is tested to ensure that the functionality is working as desired and that any errors in the code are properly handled. It is usually done after the unit testing of individual modules, and before a more thorough system test of the entire product under load/stress conditions."
"There are many testing tools in the marketplace that offer a lot of functionality to help with the testing efforts. However, they need to be obtained, installed, and configured, which could take up valuable time and effort. Bash can help to speed things along."
Functions and aliases in bash" also http://www.linuxgazette.com/issue53/eyler.html
Variable Mangling in Bash with String Operators LG #57 by Pat Eyler (see also Variable Mangling in Bash with String Operators)
Have you ever wanted to change the names of many files at once? How about using a default value for a variable if it has no value? These and many other options are available to you through string operators in bash and other bourne shell derived shells.
String operators allow you to manipulate the contents of a variable without having to write your own shell functions to do so. They are provided through 'curly brace' syntax. Any variable can be displayed like this ${foo} without changing its meaning. This functionality is often used to protect a variable name from surrounding characters.
bash-2.02$ export foo=foo
bash-2.02$ echo ${foo}bar # foo exists so this works
foobar
bash-2.02$ echo $foobar # foobar doesn't exist, so this fails
bash-2.02$
By the end of this article, you'll be able to use it for a whole lot more.
There are three kinds of variable substitution:
- Pattern Matching,
- Substitution,
- Command Substitution.
I'll talk about the first two and leave command substitution for another article. ... If you're interested in more hints about bash (or other stuff I've written about), please take a look at my home page.
Column - Ed Schaefer - The Shell Corner -- Each month UnixReview.com will publish a selected script in this column. I will evaluate the submissions and award each winner $100.00 courtesy...
Welcome to the inaugural edition of the Shell Corner column. The premise of Shell Corner is simple: You, the Unix professional send in your favorite Unix shell script and each month UnixReview.com will publish a selected script in this column. I will evaluate the submissions and award each winner $100.00 courtesy of UnixReview.com. What could be more simple?
Joe Casad, UnixReview.com senior editor, wanted a "shell guru" to author this column, but ended up with me instead. My experience is mostly as a Unix business applications programmer and not as a systems administrator. I feel my attitude is more minimalist than most, and my script evaulations are certain to reflect this. I enjoy scripts that are (relatively) easy to read and well documented. If I have trouble reading a script, chances are I'll quickly go to the next one.
What are the limitations on script submissions? I can think of no limitation, other than length. Use any of the Unix tools such as Perl, awk, sed, etc, as well as high level languages, such as C or C++. I'll even struggle through assembler if you will.... ... ...
# tolower.sh: convert file names to lower case # in the current working directory # Choose either all the files in a directory or a command-line list if [ "$#" -gt 0 ]; then filelist="$@" # just the files on command line else filelist=`ls` # all files fi for file in $filelist; do # Use the grep command to determine if the file has an upper case letter # Determine the destination of the mv command by down shifting all the # letters in the file name. Command substituting an echo of the # file name to the translate filter, tr, performs the downshift if echo "$file"|grep [A-Z] > /dev/null; then mv "$file" `echo "$file"|tr "[A-Z]" "[a-z]"` fi done
Bourne Shell Programming by Robert P. Sayle
Some useful shell links
- Mailing From Scripts(Jul 29, 2000) About.com: Calling Commands When Booting [init script](Jul 29, 2000)
- Linux Gazette: The Deep, Dark Secrets of Bash(Jul 08, 2000)
- Linuxnewbie.org: Bash Programming Cheat Sheet(Jun 14, 2000)
- IBM developerWorks: Bash by example, Part 2(Apr 09, 2000)
- Linux Gazette: Introduction to Shell Scripting--The Basics(Apr 02, 2000)
- shellscript.org: Share UNIX/Linux scripts/applets(Apr 00, 2000) I
- BM developerWorks: Bash by example, Part 1(Mar 30, 2000)
- Ext2: Shell Scripting Part One (Feb 27, 2000)
*** Of Unix shells and environment variables -- Mo Budlong small tutorial.(2,200 words)
Copyright © 1996-2008 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
Standard disclaimer: The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.
Last modified: March 15, 2008