Road Bash is a portable bash command shell for Unix, Windows, and Mac OS. It contains scripts for initializing the Bash shell, logging, and error handling. For standalone operation under Windows, Road Bash redistributes MSYS and selections from GnuWin32, Outwit, and UnxUtils.
Please send comments and suggestions to bradb@shore.net
Road Bash
- Setup Road Bash (here)
- Road Bash shell (here)
- Road Bash script (here)
- Unix commands for Windows (here)
- Command line help (Road) -- FAQ and Hints
- COPYING, README, README (local), Changes
- sh files -- bashenv, bashrc, make, script, test
Learning Bash
- Garrels' Bash guide for beginners
- Gmikkey's Bash Programming Introduction
- Learning the shell -- linuxcommand.org
- Linux Cookbook's The Shell
- Streicher's Speaking Unix
Help
- Bash (wikipedia)
- MinGWiki Help for MinGW and MSYS
- Manual and Home for Bash
- Unix man -- CuresCancer (searchable), Cygwin, FreeBSD (searchable), GNU, LinuxManPages (searchable), MacOS, SGI (searchable), SS64, SuperMan
- Microsoft, SS64
Advanced Bash
- Bash FAQ and #bash FAQ
- Bash Pitfalls
- Cooper's Advanced Bash-Scripting Guide
- Barnett's Grymoire tutorials on Bash, SED, and AWK
- Bashdb -- Bash debugger
- Bash Shell Startup Files from Beyond Linux from Scratch
Acknowledgements: Many thanks to MinGW, Akamai, PTC, Mathsoft, LTSave, and the Road team at ATG. Page design by Dave Marshall. Logo by T.W. Walsh.
Copyright (c) 2005-2009, Road Intranet
Setup Road Bash
To set up Road Bash
-
On Windows -- Download
road-bash.zip
[Upper-left on this page]. Extract the zip file toC:\
, preserving the file paths. Click on the bash icon (a green tree). -
On Unix or Cygwin -- Download
road-bash.tgz
[Upper-left on this page]. From your home directory, executetar -zxf road-bash.tgz
orgtar -zxf road-bash.tgz
. Copybash/etc/skel/.bashrc
to your home directory. Executesh --login
orbash --login
-
On Macintosh -- Download
road-bash.tgz
. Extract the contents to the Desktop. Then move thebash
directory toUsers/your_login
, and copybash/etc/skel/.bashrc
to the same directory. LaunchApplications/Utilities/Terminal
. Alternatively, launchTerminal
and follow the Unix instructions. - HOST-~> -- The command prompt should be the machine name followed by '-~'
- finda -- List the aliases and functions defined by Road Bash.
- road-test.sh (bash/local/bin/road-test.sh) -- Run this command to test your bash installation.
-
The following errors may occur
-
If the command prompt is "sh-3.1$" -- The bash startup script,
bash/etc/road-bashrc.sh
did not run. Try sourcing the file directly. Checketc/profile
. It is executed before road-bashrc.sh -
: command not found -- Bash is expecting Unix line endings (\n), but .bashrc and/or
etc/road*.sh use Windows line endings (\r\n). Use the Unix distribution, or convert the
files using
d2u
. - parse error near ']]' -- You are running zsh instead of bash.
- road-test.sh: bad substitution -- /bin/sh is csh instead of bash. Change the first line of road-test.sh to "#!/bin/bash"
- road-test.sh reports an error -- Look at the detailed log file. Typically a Unix command requires different arguments. If you find an error in Road Bash, please report it to bradb@shore.net.
-
terminal is not fully functional -- ~/.termcap is not defined for
less
andmore
. Copy it frombash/etc/skel/.termcap
.
-
If the command prompt is "sh-3.1$" -- The bash startup script,
-
On Windows, install additional utilities -- Install Windows utilities into
c:\bash\util
and Unix utilities intoc:\bash\local
. See Suggested utilities for Windows -
Windows command shell -- To invoke bash programs from the Windows command shell, append
the following to the PATH variable:
;c:\bash\util;c:\bash\bin;c:\bash\local\bin
[Control Panel->System->Advanced->Environment Variables
]. Execute bash.bat to switch the Windows command shell to bash. -
Simplified distribution on Unix, MacOS, or Cygwin -- Copy
bash/etc/road-*
to/etc
If using a standard SSH login, copyroad-root.bash_profile
to its home directory. Otherwise copyroad-home.bashrc
to home directories or/etc/skel
. - bash --init-file /etc/road-home.bashrc -l -c "finda find" -- Setup road-bash at launch.
For documentation, use Siever, et. al., Linux in a Nutshell, O'Reilly, 2005, ISBN 0-596-00930-5.
Road Bash shell
Road Bash sources etc/road-bashenv.sh
and
etc/road-bashrc.sh
Navigation
- b -- back to previous directory
- c dir -- CDPATH includes .., ../.., etc.
- c1,c2,c3,c4,c5,c6 -- go up n directories
- cc dir -- cd dir; ls
- cdw 'dir' -- cd to Windows or Unix directory
- dir -- launch Windows explorer
Search (egrep)
- finda alias -- find matching aliases and functions
- findd dir [name] -- find matching subdirectories by egrep and name
- finde env -- find matching environment variables
- findf file [name] -- find matching files by egrep and name
- findh history -- find matching history
- findmy x -- find matching namedir
- findp process -- find matching process
- findt text [name] -- find matching file lines [egrep] that match name, cut at 150
- findtt text -- find files that match text [egrep] and name
- findx xfile [name] -- find files that match name, but not xfile [egrep]
- findxt xfile text [name] -- find matching file lines that match name but not xfile [egrep]
- findxtt xfile text [name] -- find files that match text [egrep] and name, but not xfile [egrep]
- ph name -- list matching lines from ~/phone.*
namedir
- mydir x -- define x and $x as current directory.
- namedir x dir -- define x and $x as dir
- findmy x -- find namedirs that match x
- rmmy x -- remove x
Files
- copy -- cp file
- del -- rm file
- dos2u -- strip \r from files
- e file -- edit file using $EDITOR
- file_swap x y -- swap file or directory names
- findf file [name] -- find matching files
- newbashenv -- Replace .bashenv with paste buffer
- newsource -- source .bashrc
- p4edit [selector] -- open modified files for edit (p4)
- p4update [--update] -- update current directory for p4
Directories
- findd dir [name] -- find matching directories
- l -- list directory in columns
- ll -- list directory, most recent last
- mydir x -- define x as an alias and variable
- newdir dir -- mkdir dir; cd dir
- setup_keychain -- set up ssh keychain
- /usr/local/bin:/bin -- added to PATH if needed for /bin/find.
- /usr/util -- added to PATH if defined.
History
- findh history -- find matching history
- h -- recent history
- hh -- full history
Road Bash scripts
road-script.sh sources etc/road-env.sh
. Source etc/road-script.sh
from
your bash scripts
source /etc/road-script.sh source ~/bash/etc/road-script.sh
Log initialization and exit
- check_err_log $LINENO file -- Create log file, exit on failure
- check_err_log_rel $LINENO file -- Allow relative path to log file
- check_isrunning -- Prevent duplicate runs by IS_RUNNING.txt
- exit_isrunning -- Delete IS_RUNNING.txt
- ro_here -- Return function and depth for logging. $LINENO does not work well within functions.
Error exit
- exit_err $LINENO msg -- Write msg, then exit
- exit_err_file $LINENO msg file -- Write msg and file, then exit
- exit_if_err $LINENO msg -- If non-zero status, write msg, then exit
- exit_if_err_file $LINENO msg file -- If non-zero status or file, write msg, then exit
- exit_if_fail $LINENO command -- Execute command, exit on failure
Compatibility
- sed_r -- Extended regular expressions for sed
- xargs_i -- Replace {} with xargs
Functions (road-bashenv.sh)
- daysago n -- Return epoch time n days ago
- idate [i] [options] -- Convert epoch time to date
- idate2 date [options] -- Convert date to epoch time
- ro_hostip -- 172.26.105.151, Return IP of host
- ro_minute -- 15:02
- ro_now -- 2005-04-21T15:02:10, primarily for logging
- ro_today -- 2005-04-21
- ro_winpath -- Convert Unix to Windows path (but not /local)
- ro_unixpath -- Convert Windows to Unix path
Logging
- log_err $LINENO msg -- Write msg to log
- log_err_file $LINENO msg file -- Write msg and file to log
- log_if_err $LINENO msg -- If non-zero status, write msg to log
- log_if_err_file $LINENO msg file -- If non-zero status or file, write msg and file to log
- log_note $LINENO msg -- Write msg to note log
- log_step $LINENO msg -- Write msg to log
Variables (road-bashenv.sh)
- EDITOR -- Invoked by 'e' (e.g., emacs, TextPad, Notepad)
- IS_BASH3 -- Set if Bash 3.0 or later
- IS_CYGWIN IS_MAC IS_MSYS IS_WINDOWS -- Set if Cygwin, Mac OS, MSYS, or Windows
- P4PORT P4CONFIG P4USER P4EDITOR -- Perforce configuration
-
HOST, USER -- Defaults to HOSTNAME, USERNAME. Usually defined by
etc/profile
- TEMP, TMP -- /var/tmp
- RO_RUN_DIR (road-script) -- Current directory at road-script.sh
- EOL (road-script) -- \r\n or \n as needed
- SEP (road-script) -- \ or / as needed
Unix commands for Windows
Road Bash redistributes MSYS with selections from GnuWin32, Outwit, and UnxUtils.
Archives
- bzip2, bunzip2 -- bz2 compressed files
- ftp (Windows), sftp -- tile transfer protocol
- gzip, gunzip -- gz compressed files
- lzma -- LZMA compression for SourceForge
- tar -- tar and tgz archive files
- wzzip, wzuin -- zip archive files
Files
- cat -- Concatenate files
- cmp -- Compare files
- chmod -- Change permissions
- comm -- Compare sorted files
- cp -- Copy files and directories
- csplit -- Split into files
- diff -- Compare text files
- diff3 -- Three-way comparison
- file -- Get file type
- find -- Find files
- head -- First n lines
- more, less -- Page output
- ln -- Link files
- ls -- List directory
- mkdir -- Make directory
- mv -- Move files
- od -- Octal or hex dump
- paste -- Paste files together by lines
- patch -- Patch files
- pwd -- Print working directory
- rm -- Remove files and directories
- rmdir -- Remove directory
- split -- Split into multiple files
- stat -- File or directory status
- tail -- Last n lines
- tail -f -- Monitor file output
- touch -- Update file modification
Windows
- cmd -- Invoke Windows cmd
- d2u -- Convert \r\n to \n in-place
- docprop -- Properties for Windows doc
- lnkcnv -- Convert .lnk file to 'ln -s'
- mkshortcut -- Make Windows shortcut
- mount, umount -- Mount Windows directory
- msysinfo -- MSYS versions, PATH, and HOME
- readlog -- Read Windows event log
- readshortcut -- Read Windows shortcut
- start -- Start Windows program
- u2d -- Inplace \n to \r\n
- winclip -- Cut and paste the Windows clipboard
- winreg -- Read and write the Windows registry
Programming
Shells and Editors
- cls -- Clear screen
- clsb -- Clear screen and buffer
- rxvt, MSYS.bat -- X terminal
- sh, bash, bash.bat -- bash shell
- vi, vim, view, rvi, rview, rvim -- Visual editor
- ex -- Edit files
- stty -- Terminal line settings
- $EDITOR -- /util/TextPad, Notepad, vim, or emacs
Text
- awk, gawk (manual, tutorial) -- Text processing language
- colrm -- Remove columns
- column -- Output in columns
- cut -- Truncate lines
- echo -- Echo
- expand, unexpand -- Expand tabs to spaces
- fmt -- Format paragraphs
- fold -- Output 80-character lines
- grep, egrep, fgrep -- Pattern match
- join -- Join files on a field
- printf -- Format output
- sed (tutorial) -- Stream editor
- sort -- Sort
- tr -- Translate characters
- tsort -- Topological sort
- uniq -- Unique lines
- wc -- Count lines and characters
Script commands
- basename, dirname -- Extract filepath components
- date -- Date
- expr -- Compute expression
- false -- Always false
- hostid -- Host ID
- hostname -- Host name
- id -- User information
- sleep -- Sleep n seconds
- tee -- Capture piped output
- true -- Always true
- uname -- System and machine version
- which -- Which file gets executed
- whoami -- User name
- xargs -- Convert filenames to arguments (c.f., find)
- yes -- Always 'y'
System
Copyright (c) 2005-2009, Road Intranet