Shell Scripts

A browser can access this directory, Scripts, for navigation and listing (click on the link in this sentence or the Section header).


This directory has a set of possibly useful shell scripts, ranging from trivial one-liners to less obvious code; provenance is cited if not local.

Other shell scripts, along with these, are in the directory ../../Code/Configuration/0burn-050529/bin (filepaths are given relative to this directory, Scripts).

A set of aliases and functions, in effect shell scripts, is to be found in the bash configuration file ../../Code/Configuration/.bash_aliases.

Directory listing

|-- 0README		obvious
|-- ap			extract man (1) = user commands from apropos output
|-- blone		compress sequences of empty lines into one empty line
|-- blout		delete all empty lines
|-- cpr-save		copy file; backup destination file first if necessary
|-- diffmk		insert change marks in text
|-- dircmp		compare directories - from AT&T code
|-- dircmp-other	compare directories - other dircmp-like scripts
|   |--
|   |--
|   `--
|-- dutree		format a du listing by piping through tac and ind
|-- ind			filter to indent output from du or find
|-- intounix		convert msdos/cpm/macos files to unix line termination
|-- makelex		compile lex code
|-- rename		rename files
|-- ttygraph		data and plot commands read from stdin or file
|-- ttygraph.awk	awk script, to process file of data and plot commands
|-- whatis-filter-jar	compact long lines, cut out garbage in whatis database
`-- why			for simple minds


usage:   ap  key-word-list

action:   filter (keep) only user commands (1) from apropos output

pipe output through whatis-filter-jar to limit line length, sort, and remove duplicate entries


usage:   blone  [filelist]

action:   replace runs of blank lines (space, form feed, or tab only) with single blank line

read from stdin or cli filelist; write to stdout


Allyn Fratkin San Diego Division
Hewlett-Packard Company uunet!ucsd!hp-sdd!allyn >/p>


usage:   blout  [filelist]

action:   delete blank lines (space or tab only)

read from stdin or cli filelist; write to stdout


usage:   cpr-save  srcfilepath  destfilepath

action:   copy file; if destination file exists, back it up before copy

if destfile exists at destfilepath, destfile renamed destfile.old

attributes preserved in copy


usage:   diffmk  [ -- ]  filename1  filename2  filename3

action:   insert change marks in text

filename1 and filename2 are old and new versions of a file

diffmk generates filename3, which is filename2 with troff markup inserted to indicate changes from filename1

there is a man page

NOTE:   diffmk was (is?) copyright AT&T code

there are versions without this copyright on the net, e.g., from opensolaris

nrchbar is a C program that does change-marks better....


usage:   dircmp  -s  -d  -wn  directory  directory

action:   compare directories

-s, do not list "same" files

-d, run diff on different files

-w, set output width at "n" (default = 72) for pretty print (pr)

there is a man page

NOTE:   dircmp was (is?) copyrighted AT&T code; there are versions on the net that are without copyright

other versions: - works, but essentially "diff" - same as AT&T code, no copyright; symlink /private/var/tmp -> /usr/tmp - closest to AT&T; strip all comments (#.... lines) before using, and convert to unix line ends

diff --brief - not equivalent to dircmp


usage:   dutree  [directory]

action:   pretty formatting of directory tree output from du

pipe output from "du -kx [$*]" through tac and ind

size of file or directory is given in parentheses, as number of 1024-byte blocks [mac osx - disk space is apportioned in 4k blocks]

mount points are not traversed

symlinks are not followed


usage:   [cat  [filepath-list,  dirpath-list]  | ]  ind  [-t]

action:   filter to indent output from du or find

-t, put filesize in left hand column, indent file hierarchy as usual; default is to place filesize in parenthesis after filename


conor rafferty, stanford
(X-Archive: comp.sources.misc/8709/10)
slightly modified by j.a. rupley, tucson, arizona


usage:   intounix  [filelist]

action:   convert text (ascii) input from msdos or cpm or macos to unix format

strip high bits;

convert cr[cr...]lf to lf, quit at first ^Z eof

convert cr to lf (for mac os x)

works as filter: read from stdin, write to stdout

works to convert all files in cli filelist: converted file overwrites original


usage:   makelex  [ lex_input_file.l  [ executable_file ] ]

action:   compile lex code

read from stdin or cli file.l; output to cli file or default = a.out

NOTE: lex one-liners (or several-liners) are great for file manipulation where patterns cross line ends


usage:   rename  [-x]  { {-l,  -u,  -nmbr}, [{-a, -p, oldstring}  {-d, newstring}] }   filelist

action:   rename a set of files:

substitute oldstring by newstring in each filename of filelist

append (-a) or prepend (-p) the newstring or a date (-d)

query before making each change, unless option (-x)

convert all to lower case (-l) or upper case (-u)

truncate filename to length = decimal number = nmbr (-nmbr)

oldstring and newstring may be regular expressions

rename preserves file attributes


usage:   ttygraph  [filelist]

action:   process data and plotting commands with awk script ttygraph.awk

read input from filelist or stdin; output to stdout


action:   awk script, to process file or stream of data and plotting commands

ttygraph.awk == graph - a processor for a graph-drawing language

input:  data and specification of a graph

output:  data plotted in specified region of screen

for structure of the input, read ttygraph.awk code, or the "awk" book


the "Awk Programming Language". by a-k-w, addison-wesley, 1988;
modified slightly by j.a. rupley, tucson, arizona


usage:   [ /usr/bin/{aproposwhatis}  keyword-list ]  |  whatis-filter-jar

action:   compact long lines and cut out garbage in whatis database

some lines of whatis database have a long list of files or a long decription

filter compacts both parts of the whatis database line if size limits are exceeded

sorts and retains only unique entries


usage:   why  [query_string]

action:   your helpful confidant

silly, and not too good at it....


Newsgroups: alt.sources
Date: 25 Jul 89 11:29:02 GMT
Reply-To: (Rolf Howarth)
converted from csh to ksh - j.a. rupley, tucson, az

bash aliases

list with bash command "alias", or extract from .bash_aliases:
   grep "^#.*[\]-" |
   sed -n -e "s/^#[ ]*//" -e "s/[ ]*\([\]\)/^H\1/" -e "s/alias for //p" \
   	-e "s/alias to//p" -e "/alias/p"| 
   sort *[\]-" |sed -n -e "s/^#[ ]*//" -e /alias/p | sort ]

	..	\- "cd .."
	H	\- grep of history list
	cd	\- UNIX cd command to local variant, c
	cdiff	\- colordiff
	cl	\- "clear"
	cx	\- "chmod +x" = change mode to executable
	dugraph	\- du|macosx-odd-char-filter|dugraph
	h	\- "fc -l", shorter mnemonic for history
	j	\- "jobs -l"
	l	\- "ls -F", listing with dir:exec marked /:*
	l1	\- "ls -adF [$*]", like "l" but no descent into subdir if $*
	li	\- "ls -il", for long ls listing
	lit	\- "ls -ilt", for time-sorted long ls listing
	lx      \-  list executable files, 5 columns, sorted across 80scol line
	lr	\- "ls -RF", for nice listing of tree
	m	\- "more", with color esc seq recognized
	p	\- "who + pwd + ps" = user and process info
	ps	\- "ps -auxc" = full ps; psxx = /bin/ps
	r	\- "fc -s", = run previous [history-numbered] command
	restty	\- reset of stty to .profile values
	rm,rmxx \- alias rm to "can", rmxx to /bin/rm
	top	\- nice set of options
	xt24	\- change to 80x24 xterm window size
	xt40	\- change to 80x40 xterm window size
	xterm24	\- spawn of 80x24 xterm window size, at lower right screen

bash functions

list with bash command "declare -[f,F]", or extract from .bash_aliases:
   cat .bash_aliases | 
   grep "^#.*[\]-" |
   sed -n -e "s/^#[ ]*//" -e "s/[ ]*\([\]\)/^H\1/" -e "s/function for //p" \
   	-e "s/function to//p" -e "/function/p"| 

	C	\- compile C programs (C adm.c expands to cc adm.c -o adm).
	apropos	\- filter of apropos output: limit line length and sort 
	back	\- pop top off stack, cd to new top = previous directory
	c	\- c [arg1 [arg2]] = cd [arg1 [arg2]] and push directory
	can	\- can [-scrfi] filelist = front end for rm; protected by
			query or mv to ../tmp
	chmog	\- set of mode+owner+group of a file
	d	\- list directory stack, current directory last
	ff	\- find name=$1 under current directory
	l.	\- "ls -dF $1 .[a-zA-Z0-9-_]*" = ls for dot files
	luc	\- "ls -adF .* [!a-z]*" = list . and uc files
	pop	\- pop [n [m]] - pop directory stack item n, or n thru m
			[default n = m = top]
	pp	\- pp [n] = move directory n to top of stack, and cd to it
			[default = exchange current and previous directories]
	psgrep	\- extraction of ps (process) info for file=$1
	push	\- push dirname = push directory onto stack
	watch	\- "tail -f[$1 | nohup.out]"
	whatis	\- filter of whatis output: limit line length and sort