bash Ease of use features

/etc/profile executed at login. system-wide set-up for all users
~./bash_profile or .profile executed. Terminal setup, environment variables (PATH, PS1),umask.
~./bashrc executed for each bash spawned. Aliases, functions and shell variables definition.
*****************************************
Previous pages of screen viewable by [Shift] PageUp or scroll bar
-------------------------------------------------------------
Mouse can drag copy (highlight) and paste (middle button) to command line or into application. Single, double, triple clicks for character, word, line highlight.
-------------------------------------------------------------
Linux virtual consoles. Alt F1, Alt F2 etc each a different terminal. X usually at Alt F7.
-------------------------------------------------------------
history of previous commands. Easily recalled and modified.
set history = 50 # here, the previous 50 cmds remembered.
History editing easier if arrow keys and editor (vi or emacs) cmds integrated as in bash and ksh (set -o vi).
Use emacs editing commands (65 of them!):
most useful:
Retrieve previous command with up arrow. Arrow keys move left and right in command line.
^A  beginning of line   Home key.
^E  end of line.            End key
^D  delete char.  Or Backspace to delete previous char.  Delete key.
^K  delete to end of line
^U  kill line (actually kernel)
Esc D  (or Alt D) delete word
!54  re-execute command #54
!la   re-execute most recent command that started with la
-------------------------------------------------------
Alias:
create new "command" by giving command another name.
alias newname=oldname
$ alias l='ls -la'
$ l
(output of ls -la here)

$ alias l='ls -la | more'
$ alias m=more
$ m myfile
(output of more here)
$ alias (to get list of all aliases )

alias 325='cd ~/umuc/classes/cmis325/students' #alias for a long path
alias all='ps -aux | more'
alias pt='enscript -B -h -f Times-Roman12 '

Typically aliases are in .bashrc so automatically available each login.
Unfortunately, bash aliases can't have arguments; but functions can.
h     history
lo    locate
j     jobs
cp    cp -i
mv    mv -i
m     more
g++   g++ -Wall -ansi
--------------------------------------------------------------------
Filename completion service.
Shell will complete the name of a file. Activate with set filec, typically in .bashrc (or is part of emacs command line editing mode).
Only have to type a prefix of filename (enough to unambiguously specify the file).
$ ls
homeassgn1
$ cat h<Tab> You type h and Tab key (or Esc twice), shell fills in rest of filename
(display of homeassgn1)

$ ls
homeassgn1
homeprob
$ cat h<Tab> since is ambiguous, shell beeps, cat home is on cmd line, waiting for
clarification, you type p<Tab>, shell completes to homeprob
(display of homeprob)
Also: completion of usernames, hostnames, shell variables, command names
bash: ^V to escape completion (when want literal tab)
-----------------------------------------------------------
Job control managing multiple programs from the shell
--switch jobs between foreground and background
--suspend a job, resume it later
If running X, not so useful (can have separate window for each program).
Stop the foreground job with ctrl-z (sends signal 18 SIGSTOP)
Run job in background with &

$ jobs
[2] Stopped vi novel
[3] - Stopped cc bigproc.c
[4] + Stopped vi bigtext
[5] Running prog1

Key:
+ marks most recently stopped job
- marks second most recently stopped job
Running is a background job

Resume most recently stopped job with fg
Resume any stopped job with fg %job_number, e.g. fg %2 or just %2
Resume a stopped job in the background with bg %job_number or %2 &
Stop a background job with stop %job_number
Terminate a job with kill %job_number
$ stty tostop #Background jobs will stop if they try to output to terminal.

-----------------------------------------------------------

Shell functions
--kept in memory (faster than script: No overhead of searching PATH, opening file from disk, spawning subshell)
--like a built-in command
--variables are global with shell unless typeset to create local variables
--private arguments (alias cannot have args in ksh/bash)
--define in environment file .bashrc, interactively, or in script
typeset -f to list them. or as part of output of set
declare -f
l() {
  ls -l $* | more
}

usage() {
  echo "Usage: et [-a name number | -d name | -p | name]"
  exit $1
}

e() {
  emacs -fg white -font 9x15bold -geometry 90x30+0+0 $* &

}

calc() {
  echo "$*" | bc -l
}
Create interactively:
function myfunname { cmds ;}