STLLUG - St. Louis Linux User Group
07/20/1995 : Linux Shells
Presenter: Matthew Feldt

The bash & tcsh shells

URL's

The tcsh shell

Setting the Prompt

%/Current working directory.
%~cwd. If it starts with $HOME, that part is replaced by a ~. In addition if a directory name prefix matches a user's home directory, that part of the directory will be substituted with ~user. NOTE: The ~user substitution will only happen if the shell has performed a ~ expansion for that user name in this session.
%c or %Trailing component of cwd, may be followed by a digit to get more than one component, if it starts with $HOME, that part is replaced with a ~.
%CTrailing component of cwd, may be followed by a digit to get more than one component, no~ substitution.
%h, %!, !Current history event number.
%MThe full machine hostname.
%mThe hostname up to the first ".".
%t or %@Current time of day, in 12-hour, am/pm format.
%TCurrent time of day, in 24-hour format. (But see the ampm shell variable below.)
%pCurrent time in 12-hour format, am/pm format with seconds.
%PCurrent time in 24-hour format, with seconds.
%%A single %.
%nThe user name, contents of $user.
%dThe weekday in <Day> format.
%DThe day in dd format.
%wThe month in <Mon> format.
%WThe month in mm format.
%yThe year in yy format.
%YThe year in yyyy format.
%Lclear from prompt to end of display or end of line.
%#A '#' if tcsh is run as a root shell, a '>' if not.
%?return code of the last command executed just before the prompt.
%RIn prompt3 this is the corrected string; in prompt2 it is the status the parser.

Shell Variables

set autolist, unset autolist
Lists possibilities on ambiguous tabs.
set correct=[all|cmd], unset correct
Spell check just commands [cmd] or [all].
set autologout=x, unset autologout
Exit shell if idle x minutes.
set tperiod=x, unset tperiod
set periodic <command>, unset periodic
Run command every tperiod minutes. tperiod=0 degenerates to precmd.
set history=x, set savehist=x
Set number of commands to save in history and in .history
sched [+]hh:mm <command>
Schedule a command to run at a predetermined time. sched by itself lists scheduled commands. sched -# deletes a scheduled command.
% sched 11:00 echo It\'s eleven o\'clock.
% sched +2:15 /usr/lib/uucp/uucico -r1 -sother
% sched 5pm set prompt='[%h] It\'s after 5; go home: >'
% sched +3am echo This syntax doesn\'t work.
Relative time inconsistent with am/pm.
set watch=([x] user tty ), unset watch
Watch user logins on determined devices. Optional time argument may precede user. Watch does not report 'su' activity.
% set watch=('ma*' console )
% set watch=( root any )
% set watch=( 10 any any )
code has logged on tty1 from local.
root has logged on tty2 from local.
matthew has logged on ttyp0 from mcfmwf.
alias precmd <command>, unalias precmd
Execute a command prior to each user command
% alias precmd date
alias beepcmd, unalias beepcmd
Execute a command every time the terminal bell is rung.
% alias beepcmd 'cat /usr/local/lib/xboing2.2/sounds/youagod.au > /dev/audio'

Command Line Interaction

bindkey
List keyboard mappings
% bindkey
Bind emacs-style editting
% bindkey -e
Bind vi-style editting
% bindkey -v
Character Expansion
tab completion (filenames, directories, environmental variables)
Control-D listing (list file names available, ~Ctrl-D lists users)
~ user name expansion, ~/ expands to users directory
History
Navigation: (arrow keys ), (Ctrl-P Ctrl-N) and (j k).
!! Refer to the previous command. This is a synonym for '!-1'.
!n Refer to command line n.
!-n Refer to the current command line minus n.
!string Refer to the most recent command starting with string.
!?string[?] Refer to the most recent command containing string.
^string1^string2^ Quick substitution replacing string1 with string2 in the last command.
% mv foo bar!#:1
mv foo barfoo
history -[cLS] clear, Load and Save.
Moving Around
Go to the last directory
% cd -
Push (pushd) or Pop (popd) a directory from the stack.
dirs -[cvLS] clear, verbose, Load and Save the directory stack.
Miscellaneous
Which command or alias will be executed.
% which
Reread file names for expansion and search path.
% rehash
Exit status of previous command.
% echo $status
Conditional chaining of commands with && and ||.
% l /xxx &> /dev/null || echo did not work
Using command output as input to another command.
% rm -f `find . -name \*.o -print`
% set var = `date`; echo $var
Job control with jobs, bg, fg, etc...

Test Expressions

Typical cshtcsh enhanced
r read access c character special file
w write access b block special file
x execute access p named pipe (fifo)*
e existence u set-user-ID bit is set
o ownership g set-group-ID bit is set
z zero size k sticky bit is set
f plain file s the file is non-zero size
d directory t open file descriptor for terminal device [a number]
l symbolic link* S socket special file*
X executable in the path or shell builtin
* if file system supports these type files

My Personal .tcshrc

set prompt='%! %T%/> '
set prompt3='CORRECT> %R (y|n|e) '
set correct=all
set path = ( . $HOME $HOME/bin $HOME/scripts /etc /bin /usr/bin \
             /usr/X11/bin /usr/local/bin /usr/local/X11/bin     \
             /usr/openwin/bin $HOME/stat/istat/bin )

setenv LESS -CeM
setenv PAGER 'exec /usr/bin/less -CeM'

# set history and save history values
set history=50 savehist=20
# Bind vi style command line editing
bindkey -v

# If this is a login prompt do this stuff
if($?prompt) then
set prompt="%! %T%/> "
if($term == "xterm" || $term == "color_xterm") then
alias cwdcmd '/bin/echo -n "^[]2;${HOST}:$cwd^G"'
endif
endif

alias l      '/bin/ls $LS_OPTIONS -lF'
alias h      'history'
alias cc     '/usr/bin/gcc -Wall -ansi -pedantic -fwritable-strings \!*'
alias cl     '/usr/bin/gcc -o `basename \!* .c` \!* -lcurses'
alias cx     '/usr/bin/gcc -o `basename \!* .c` \!* -lX11'
alias cxt    '/usr/bin/gcc -o `basename \!* .c` \!* -lXaw -lXmu -lXt -lXext -lX11'
alias cxm    '/usr/bin/gcc -o `basename \!* .c` \!* -lXm -lXmu -lXt -lXext -lX11'
alias man    '/usr/bin/man -a \!*'
alias md     'mkdir \!*'
alias m      'less \!*'
alias manf   '/usr/bin/groff -Tascii -mandoc \!* | less'
alias fs     '/usr/bin/grep \!* *.[ch] | /bin/more'
alias bc     '/usr/bin/bc -l'
alias pview  'latex \!* && xdvi `basename \!* .tex`.dvi'

The bash shell

Setting the Prompt

\t the current time in HH:MM:SS format
\d the date in "Weekday Month Date" format (e.g., "Tue May 26")
\n newline
\s the name of the shell, the basename of $0 (the portion following the final slash)
\w the current working directory
\W the basename of the current working directory
\u the username of the current user
\h the hostname
\# the command number of this command
\! the history number of this command
\$ if the effective UID is 0, a #, otherwise a $
\nnn the character corresponding to the octal number nnn
\\ a backslash
\[ begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\] end a sequence of non-printing characters

Shell Variables

SHLVL
Incremented by one each time an instance of bash is started.
IFS
Internal Field Seperator. Variable that is used for splitting lines into words with the builtin read command.
MAIL, MAILCHECK
MAIL determines the location of a mail file to be checked every MAILCHECK seconds.
HISTSIZE, HISTFILESIZE
The maximum number of lines for the active and file history.
HOSTFILE
A file of the same format as /etc/hosts that is appended to the contents of the host database on the next hostname completion.

Command Line Interaction

Character Expansion
Tab completion (filenames, directories, environmental variables).
Pressing tab twice for ambiguous expansions lists options.
~ user name expansion, ~/ expands to users directory
History
Navigation: (arrow keys ), (Ctrl-P Ctrl-N) and (j k).
!! Refer to the previous command. This is a synonym for '!-1'.
!n Refer to command line n.
!-n Refer to the current command line minus n.
!string Refer to the most recent command starting with string.
!?string[?] Refer to the most recent command containing string.
^string1^string2^ Quick substitution replacing string1 with string2 in the last command.
!# The entire command line so far.
Moving Around
Go to the last directory
$ cd -
Push (pushd) or Pop (popd) a directory from the stack.
dirs [+/-n] + shows entries from the left, - shows entries from the right.
Redirection
Standard out
$ ls > dirlist
Standard error
$ ls > dirlist 2> errorlog
Both to same place
$ ls > dirlist 2>&1 or $ ls &> dirlist
Miscellaneous
Which command or alias will be executed.
$ type <command>
Reread path and executable databases.
$ source .profile or . .profile
Exit status of previous command.
$ echo $?
Process id of the current shell.
$ echo $$
Conditional chaining of commands with && and ||.
$ l /xxx &> /dev/null || echo did not work
Using command output as input to another command.
$ chmod 644 `ls *.html`
$ VAR=`date '+%d %b %Y'`; echo $VAR
Job control with jobs, fg, bg, etc...

Test Expressions

-b True if file exists and is block special.
-c True if file exists and is character special.
-d True if file exists and is a directory.
-e True if file exists.
-f True if file exists and is a regular file.
-g True if file exists and is set-group-id.
-k True if file has its ``sticky'' bit set.
-L True if file exists and is a symbolic link.
-p True if file exists and is a named pipe.
-r True if file exists and is readable.
-s True if file exists and has a size greater than zero.
-S True if file exists and is a socket.
-u True if file exists and its set-user-id bit is set.
-w True if file exists and is writable.
-x True if file exists and is executable.
-O True if file exists and is owned by the effective user id.
-G True if file exists and is owned by the effective group id.

My Personal .profile

PS1="\! \t\w> "
PATH=".:$HOME/bin:$PATH:$HOME/scripts"

export LESS=-CeM
export PAGER="/usr/bin/less -CeM"
export HISTFILESIZE=100
export HOSTFILE="$HOME/ect/hosts"

#bind vi style editting
set -o vi

alias l='ls -alF'
alias xtitle='/bin/echo -n "^[]2;$PWD^G"'
alias h='history'

if [ "$TERM" = "xterm" ]
then
  cd()
  {
    builtin cd ${1+"$@"} && xtitle
  }
fi