BASH GNU Bourne Again SHell


http://murga-linux.com/puppy/viewtopic.php?t=44123

Bash Guide for Beginners
How to learn Bash commands
BashDiff - Bash extended
Bash Programming Cheat Sheet
http://ad.hominem.org/log/2006/02/7_bash_tips.php

Appendix

AzBash
ash is a small inbuilt shell of busybox.
Busybox is used when Puppy boots, it allows to keep the initial ramdisk small.
Busybox is a binary, that includes several commands, that else are only available as seperate programs.
But this small size has a price: not the full set of options of these programs are available.

So when Puppy booted, it additionally offers the bash, that is loaded from the big file pup_2xx.sfs.
Bash compatibility is required by several programs.

Other shells like ksh or csh have specialized capabilities like support for mathematic functions.
You will find those on university systems.
We had one program once, that required csh, so you can extract it from this archive:
http://dotpups.de/files/unsorted-not-packaged/bsd-csh.tgz

The original limited sh is used no longer, it usually is just a symlink to one of the others like the Bash (Bourne again shell), that has become quasi standard in Linux, as it is part of the GNU Utilities from the Free Software Foundation.
The FSF has rewritten several Unix-tools under a free license.
What we commonly know as "GNU/Linux" usually is the Kernel (the "real" Linux) plus the GNU Utilities like bash.

Shell

ash or bash in Puppy (others exist, such as Korn and C shells)
See also: ShellScripts

sh is the default shell, which in 1.0.5 and 1.0.6 is ash or bash
(In 1.0.6, SHELL seems to point to bash, but the command line seems to nevertheless default to ash.)

ash is the simplified BusyBox version of bash (BusyBox v0.60.5 in 1.0.6)

Bash, an acronym for "Bourne−Again Shell" and a pun on Stephen Bourne's now classic
Bourne Shell. Bash has become a de facto standard for shell scripting on all flavors of UNIX.
The bash is GNU bash 3.00.0(1) in 1.0.6.

http://www.gnu.org/software/bash/bash.html
http://www.tldp.org/LDP/abs/abs-guide.pdf
Advanced Bash−Scripting Guide. An in−depth exploration of the art of shell scripting.
http://www.gnu.org/software/bash/manual/bashref.html

Misc

The X File (Written by Martin Streicher)
To run X clients securely, use ssh -Y host. DISPLAY is automatically set to encrypt and tunnel X protocol back to the X server.

Rename With Impunity
Do you need to change the extension of many files at a time? Nothing is faster than zsh -c "autoload zmv; noglob zmv -W *.a *.b".

Jump Back (Written by Aram Yegenian)
To go back to the last directory you visited, simply type cd -. (Thanks to Aram Yegenian)

Contract Killer
Want to kill a process the quick and easy way? Try killall /path/to/file, which kills all processes executing /path/to/file.

Shred a File
To delete a file securely, first overwriting its contents (25 times), run shred -u -z -v file.

Expire Passwords
Improve system security by expiring user passwords from time to time. The command passwd -x 30 joe forces joe to change his password after thirty days.

Directories Made Easy
Use mkdir -p to create a hierarchy in one fell swoop. For example, mkdir -p a/b/c/d makes directory d in directory c in directory b in directory a.

Group-ies
To see the list of groups you're a member of, use id -Gn. id has effectively replaced groups and whoami.

What Timezone Is It?
If you want to know the proper name of your current time zone, run the interactive command tzselect. Follow the prompts and use the output in your shell login file.

Faster, Simpler Version Control
Tired of CVS? Try darcs. Creating a repository with darcs is as easy as cd ~/myproject; darcs init; darcs add -r *. Use apt-get install darcs to install or see the darcs wiki for source, tools, and more info.

Watch, Again (Written by Thomas Materna)
Reader Thomas Materna says: If you use watch to monitor the output of a command that contains wildcards, enclose the command in quotes so the expansion is made every time. For example, watch "ls *.gz" shows new *.gz files as they're created, whereas watch ls *.gz only shows the *.gz files that exist at the moment you run watch.

A Smart Man (Written by Håkon Karsten Eide)
If you want to look at a compressed log file (.gz), use man. For example, man ./auth.log.1.gz shows the contents of the log file. (Thanks to Håkon Karsten Eide.)

Look at Files in Reverse
To look at a log in reverse (most recent events first), run tac logfile | less. tac reverses the lines of any file. Use tac - to read from stdin.

Move Wisely
If you're not careful, mv can overwrite existing files. Move files wisely with mv --backup=existing -v. To save typing, set VERSION_CONTROL to existing.

Bash Quick Copy (Written by Steve Fox)
In bash, the command-line incantation cp snark{,.bak} copies snark to snark.bak. (Thanks to Steve Fox.)

Command Redux
To run a command again and again and see what's different each time, use the clever watch. For example, watch -d ls -l runs ls -l every two seconds and displays "diffs."

Spying on "Noisy" Files
If you move files from other operating systems to Linux, the files may contain odd, unprintable characters. To reveal control characters, non-ASCII characters, and so on, use either cat -e filename or od -c filename.

Temporary Files Made Easy
Need a reliable way to choose a unique temporary file? Use tempfile. For instance, tempfile -p martin creates /tmp/martiOzXxwL with mode 0600.

Another Fast Backup (Written by Morvan Bliasby)
To make a fast backup, say, of all system .conf files, combine locate, grep, and zip as in locate .conf | grep /etc/ | zip zipfile -@

Create a Tarball
A so-called tarball is a gzip-compressed tar archive. You can create one quickly with tar zcvf tarball.gz files.... To unpack a tarball, use tar zxvf tarball.gz.

Are You Sure?
Many commands that affect the file system, such as ln, mv, and rm, have -interactive options (abbreviated by -i). Use -interactive mode to approve each operation.

Who, What, When?
Need to know what makes your machine tick? Just type uname -a to see your machine's hostname, kernel version number, processor type, and more. Also see the commands arch, hostname, env, kernelversion, and ifconfig.

Update Debian
If you use Debian Linux, don't forget to run apt-get update; apt-get upgrade at least once a week to pick up the latest and greatest packages and security patches.

Tune In the Tube (Written by Johan Eriksson)
Watch a lot of TV? Tired of missing Most Extreme Elimination Challenge? Reader Johan Eriksson recommends Maxemum TV-Guide, a free KDE application that browses the television broadcast schedules of several countries.

Add Users En Masse
You can quickly create new user accounts or update existing accounts with the newusers command. Create a list of accounts in a passwd-like file and run the command newusers file.

Tee for Two (or Three, Four, ...)
To watch the output of a command and capture the output in a file, use tee. For example, find / -name '*.pm' -print | tee log lets you watch the results and keep the results in log. Use –a to append.

Links in a Snap
Use cp -l to make links to existing files. You can even use cp -rl to create a shadow of an entire directory tree.

Modes Made Easy
In addition to octal numeric modes (such as 644), chmod also supports a symbolic mode that can set and incrementally add or remove permissions. For example, chmod g+w adds group write without changing other permissions, chmod o-a removes all permissions for other, while chmod u=rw gives read/write permission only to the file's owner (and is the equivalent of setting mode 600).

Customized File Metadata
Build your own view of file metadata (permissions, file name, file size, and so on) with the stat command. Use -c (or --format=) to display the fields you want, in the order you want -- perfect for processing with scripts!

Beware Root
Avoid logging in as root. Instead, use sudo to run individual commands as the superuser. As Spider-man says, "With great power comes great responsibility."

Which Which is Which?
If you want to know all of the locations of a particular command in your PATH, use which -a command. The result is a list of filenames in PATH order.

Disable A User Account
To temporarily disable a user account, run password -l username. To re-enable an account, use the -u option.

Process Lookup Made Very Easy
Need to find or kill a process? Use the utilities pgrep and pkill. For example, the command pkill -INT -u root sshd sends the INT signal to the sshd process owned by root. For puppy 2.10, use menu/control panel/KP manage system processes for a graphical interface to all your processes.

Easy Parsing
If you have a comma-delimited file, use cut -s -d, -f n file to extract the nth field from each line of file. The -s option skips lines without the delimiter.

Less is Much More
Here's a way to save some typing: pipe the output of a command to less -Ofile, as in find / -name '*.pl' | less -Operlfiles. The option -Operlfiles automatically copies stdin to the file perlfiles.

Unique Temporary Filenames
Shell scripts often use temporary files to store transient data. To ensure the novelty of each temporary filename, append a qualifer such as $$, the current process ID, to the filename.

Compressed File Tools
View and process a gzip-compressed file (such as an archived log file) without expanding it using zcat, zdiff, zmore, zless, zcmp, zgrep, zegrep, and zfgrep.

Download from the Command-Line
wget is an invaluable utility. Use it from the command-line or a shell script to download a web page, an entire web site, a tarball, or just about any http: or ftp: URL. wget can also help debug HTTP and FTP connection problems.

Watch a Log File
If you want to watch a log file, use tail -F. The -F option prints new content as it's appended (like -f), but also re-opens a file if it's created anew, as occurs when a log file is rotated.

Perl One-Liner
You don't have to know Perl to use Perl. The command-line perl -p -i -e 's/oldstring/newstring/g' * replaces all occurrences of oldstring with newstring in all files in the current directory and makes backup copies of the original files.

Instant Environment Variable (Written by Jerry Peek)
If you use bash, you can set an environment variable for a single command by setting the variable before the command, like this: VISUAL=/usr/bin/emacs ci -l foo.txt

Copy a Directory
Need to make a verbatim copy of a directory? Use the command (cd /old/directory; tar cf - .) | (cd /new/directory; tar xf -)

Find Any File Fast
Need to find a system configuration file but only remember a part of its name? Use locate. It's faster than running find / ... and much simpler to use. (Run updatedb often to keep the locate file database up-to-date.)

Reference the Directory Stack
If you use pushd and popd to maintain a directory stack, use ~n on the command-line to reference the nth element of the stack with (where n is 0, 1, 2, and so on).

Run a Job at Boot
Written by Martin Streicher
If you want to run a command every time your machine boots, but don't have access to the init scripts, use cron's @reboot qualifier.



Index of the Ash command line

This is a list of the commands used in the Ash shell which is used by Puppy. This man page is not intended to be a tutorial or a complete specification of the shell.

Built-in Commands

alias : allows defining and viewing of aliases
bg : Run job in the background
break : Break out of enclosing loop bodies (while, until or for)
builtin : Lists all defined builtin commands, and indicates hidden, and internal
cd : chdir : Change the current working directory to that given.
continue : Continue execution at the begining of the enclosing loop
eval : Provides for multiple processing of arguments.
exec : The given program is executed.
exit : Terminate the shell,
export : Prints a list of or marks for export all the variables listed.
false : Any arguments are ignored and the return status is set to 1.
fc : Lists, or edits and re-executes, commands previously entered.
fg : continue the named job (or the current job) in the foreground.
hash : Remember the full pathname of a name argument.
help : Prints out list of Ash commands.
jobs : This command lists out all the background processes which are children of the current shell process.
kill : Stop a processs from running.
let : Perform arithmatic on
local : Create variables.
pwd : Print the current directory you are working in.
read : Read from standard input.
readonly : Mark functions or variables as read only.
return : Exit a shell function.
set : Manipulate shell variables and functions.
setvar : Assigns value to variable.
shift : Shift positional parameters.
times : User and system times.
trap : Run a command when a signal is set.
true : Do nothing sucessfully.
type : Describe a command.
ulimit : Limit user resources.
umask : Mask to create user files.
unalias : Remove an alias.
unset : Remove variable or function names.
wait : Wait for the specified job to complete and return the exit status of the last process in the job.



Overview

The shell is a command that reads lines from either a file or the terminal, interprets them, and generally executes other commands. It is the program that is running when a user logs into the system (although a user can select a different shell with the chsh(1) command). The shell implements a language that has flow control constructs, a macro facility that provides a variety of features in addition to data storage, along with built in history and line editing capabilities. It incorporates many features to aid interactive use and has the advantage that the interpretative language is common to both interactive and non-interactive use (shell scripts). That is, commands can be typed directly to the running shell or can be put into a file and the file can be executed directly by the shell.

Invocation

If no args are present and if the standard input of the shell is connected to a terminal (or if the -i flag is set), the shell is considered an interactive shell. An interactive shell generally prompts before each command and handles programming and command errors differently (as described below). When first starting, the shell inspects argument 0, and if it begins with a dash '-', the shell is also considered a login shell. This is normally done automatically by the system when the user first logs in. A login shell first reads commands from the files /etc/pro­file and .profile if they exist. If the environment variable ENV is set on entry to a shell, or is set in the .profile of a login shell, the shell next reads commands from the file named in ENV. Therefore, a user should place commands that are to be executed only at login time in the .profile file, and commands that are executed for every shell inside the ENV file. To set the ENV variable to some file, place the following line in your .profile of your home directory

ENV=$HOME/.shinit; export ENV

substituting for `.shinit ' any filename you wish. Since the ENV file is read for every invocation of the shell, including shell scripts and non-interactive shells, the following paradigm is useful for restricting commands in the ENV file to interactive invocations. Place commands within the `case ' and `esac ' below (these commands are described later):

case $- in *i*)
# commands for interactive use only
...
esac

If command line arguments besides the options have been specified, then the shell treats the first argument as the name of a file from which to read commands (a shell script), and the remaining arguments are set as the posi­tional parameters of the shell ($1, $2, etc). Otherwise, the shell reads commands from its standard input.

Argument List Processing

All of the single letter options have a corresponding name that can be used as an argument to the '-o' option. The set -o name is provided next to the single letter option in the description below. Specifying a dash `- ' turns the option on, while using a plus `+ ' disables the option. The following options can be set from the command line or with the set(1) builtin (described later).

-a allexport
Export all variables assigned to. (UNIMPLEMENTED for 4.4alpha)

-C noclobber
Don't overwrite existing files with `>'. (UNIMPLEMENTED for 4.4alpha)

-e errexit
If not interactive, exit immediately if any untested command fails. The exit status of a command is considered to be explicitly tested if the command is used to control an if, elif, while, or until; or if the command is the left hand operand of an ``&& or ``|| operator. -f noglob Disable pathname expansion.

-n noexec
If not interactive, read commands but do not exe­ cute them. This is useful for checking the syntax of shell scripts.

-u nounset
Write a message to standard error when attempting to expand a variable that is not set, and if the shell is not interactive, exit immediately. (UNIM­PLEMENTED for 4.4alpha)

-v verbose
The shell writes its input to standard error as it is read. Useful for debugging.

-x xtrace
Write each command to standard error (preceded by a '+ ') before it is executed. Useful for debugging.

-I ignoreeof
Ignore EOF's from input when interactive.

-i interactive
Force the shell to behave interactively.

-m monitor
Turn on job control (set automatically when inter­active).

-s stdin
Read commands from standard input (set automati­cally if no file arguments are present). This option has no effect when set after the shell has already started running (i.e. with set(1)).

-V vi
Enable the built-in vi(1) command line editor (dis­ ables -E if it has been set).

-E emacs
Enable the built-in emacs(1) command line editor (disables -V if it has been set).

-b notify
Enable asynchronous notification of background job completion. (UNIMPLEMENTED for 4.4alpha)

Lexical Structure

The shell reads input in terms of lines from a file and breaks it up into words at whitespace (blanks and tabs), and at certain sequences of characters that are special to the shell called `operators '. There are two types of operators: control operators and redirection operators (their meaning is discussed later). Following is a list of operators:

Control operators: & && ( ) ; ;; | || <newline>

Redirection operator: < > >| << >> <& >& <<- <>

Quoting

Quoting is used to remove the special meaning of certain characters or words to the shell, such as operators, whitespace, or keywords. There are three types of quot­ing: matched single quotes, matched double quotes, and backslash.

Backslash

A backslash preserves the literal meaning of the following character, with the exception of . A backslash preceding a is treated as a line continuation.

Single Quotes

Enclosing characters in single quotes preserves the lit­eral meaning of all the characters (except single quotes, making it impossible to put single-quotes in a single-quoted string).

Double Quotes

Enclosing characters within double quotes preserves the literal meaning of all characters except dollarsign ($), backquote (`), and backslash (\). The backslash inside double quotes is historically weird, and serves to quote only the following characters: $ ` " \ . Otherwise it remains literal.

Reserved Words

Reserved words are words that have special meaning to the shell and are recognized at the beginning of a line and after a control operator. The following are reserved words:

! elif fi while case
else for then { }
do done until if esac

Their meaning is discussed later.

Aliases

An alias is a name and corresponding value set using the alias(1) builtin command. Whenever a reserved word may occur (see above), and after checking for reserved words, the shell checks the word to see if it matches an alias. If it does, it replaces it in the input stream with its value. For example, if there is an alias called `lf ' with the value `ls -F ', then the input

lf foobar <return>

would become

ls -F foobar <return>

Aliases provide a convenient way for naive users to create shorthands for commands without having to learn how to create functions with arguments. They can also be used to create lexically obscure code. This use is discouraged.

Commands

The shell interprets the words it reads according to a language, the specification of which is outside the scope of this man page (refer to the BNF in the POSIX 1003.2 document). Essentially though, a line is read and if the first word of the line (or after a control operator) is not a reserved word, then the shell has recognized a sim­ple command. Otherwise, a complex command or some other special construct may have been recognized.

Simple Commands

If a simple command has been recognized, the shell per­forms the following actions:

  1. Leading words of the form `name=value ' are stripped off and assigned to the environment of the simple command. Redirection operators and their arguments (as described below) are stripped off and saved for processing.
  2. The remaining words are expanded as described in the section called 'Expansions', and the first remaining word is considered the command name and the command is located. The remaining words are considered the arguments of the command. If no command name resulted, then the `name=value ' variable assignments recognized in 1) affect the current shell.
  3. Redirections are performed as described in the next section.

Redirections

Redirections are used to change where a command reads its input or sends its output. In general, redirections open, close, or duplicate an existing reference to a file. The overall format used for redirection is:

[n] redir-op file

where redir-op is one of the redirection operators men­tioned previously. Following is a list of the possible redirections. The [n] is an optional number, as in '3' (not '[3]'), that refers to a file descriptor.

[n]> file
Redirect standard output (or n) to file.

[n]>| file
Same, but override the -C option.

[n]>> file
Append standard output (or n) to file.

[n]< file
Redirect standard input (or n) from file.

[n1]<&n2
Duplicate standard input (or n1) from file descriptor n2.

[n]<&-
Close standard input (or n).

[n1]>&n2
Duplicate standard output (or n) from n2.

[n]>&-
Close standard output (or n).

[n]<> file
Open file for reading and writing on standard input (or n).

The following redirection is often called a "here-docu­ment".

[n]<< delimiter
here-doc-text...
delimiter

All the text on successive lines up to the delimiter is saved away and made available to the command on standard input, or file descriptor n if it is specified. If the delimiter as specified on the initial line is quoted, then the here-doc-text is treated literally, otherwise the text is subjected to parameter expansion, command substitution, and arithmetic expansion (as described in the section on "Expansions"). If the operator is `<<- ' instead of `<< ', then leading tabs in the here-doc-text are stripped.

Search and Execution

There are three types of commands: shell functions, builtin commands, and normal programs -- and the command is searched for (by name) in that order. They each are executed in a different way. When a shell function is executed, all of the shell posi­tional parameters (except $0, which remains unchanged) are set to the arguments of the shell function. The variables which are explicitly placed in the environment of the com­mand (by placing assignments to them before the function name) are made local to the function and are set to the values given. Then the command given in the function defi­nition is executed. The positional parameters are restored to their original values when the command com­pletes. This all occurs within the current shell.

Shell builtins are executed internally to the shell, without spawning a new process.

Otherwise, if the command name doesn't match a function or builtin, the command is searched for as a normal program in the filesystem (as described in the next section). When a normal program is executed, the shell runs the pro­gram, passing the arguments and the environment to the program. If the program is not a normal executable file (i.e., if it does not begin with the "magic number" whose ASCII representation is "#!", so execve(2) returns ENOEXEC then) the shell will interpret the program in a subshell. The child shell will reinitialize itself in this case, so that the effect will be as if a new shell had been invoked to handle the ad-hoc shell script, except that the loca­tion of hashed commands located in the parent shell will be remembered by the child.

Note that previous versions of this document and the source code itself misleadingly and sporadically refer to a shell script without a magic number as a "shell proce­dure".

To read the rest of this documentation in Puppy go to Start / Help scroll down to Systems-level programs documentation and click on Ash, the shell used by Puppy.

http://www.wlug.org.nz/Shell
http://www.wlug.org.nz/ash(1)
http://linux.about.com/library/cmd/blcmdl1_ash.htm
http://www.debian.org/doc/manuals/reference/ch-program.en.html
http://www.phenix.bnl.gov/WWW/offline/tutorials/debuggingTips.html Ash Shell



Categories
CategoryProgramming
CategorySoftware

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki , online since July 19, 2009.