Title: Customizing the environment The different shells
1Customizing the environmentThe different shells
2Which shell?
- User can choose his/her shell of preference
- sh (Bourne), ksh (Korn), bash (Bourne Again), csh
(C-shell), tcsh (T shell) are options - Commonly divided into Systems programming and
Application programming shells
3Which shell? Differences
- Each shell has internal (built-in) and external
command that might behave somewhat different - Environment variables further modify the behavior
of each shell - Shell is your interface with the Kernel, so
choose one that suits your style
4Find the differences
- The chsh (change shell) command is available in
some systems to change your default shell - Not in apache.utdallas.edu.Contact your
Administrator to change your default shell, but
first test drive it - ksh and csh will be covered here
5Systems vs. application
bash (Bourne again)
6Korn Shell (ksh)
- Created by David Korn under contract for ATT in
1985. - Incorporates the syntax of Bourne Shell for most
portability (superset) - Is the fastest for executing scripts (500 more
than csh and up to 15000 more than Bourne)
7ksh Features
- String functions similar to BASIC
- Variable typing (string, int, right-just, etc)
- Variable assignment (value when declared)
- Automatic menu creation function (select)
- Functions
- Arithmetic evals (increment and decrement)
- Command editing using vi(1) or emacs(1G)
8Running/exiting ksh
- In order to run a ksh you type it in the command
line - ksh
-
- To return to your original shell
- exit
-
9Variables
- Assigning a value
- VAR110
- VAR1VAR2
- Null value, useful for testing conditions
- VAR2
- To view the contents
- print VAR1
- 10
- Environment variable
- PATHPATH/usr/bin
- Note no spaces allowed around
10 Exporting variables
- var110
- print var1
- 10
- ksh
- print var1
- exit
- export var1
- export var220
- ksh
- print var1 var2
- 10 20
null value
set and export in the same line
11set command
- View a list of local and environment variables
values - set
- PATH /usr/bin..
-
- var10
- Set and unset Korn shell attributes
- set -o lists attributes and their
state (on/off) - set -o option enables the option
- set o option disables the option
12set command
- To automatically export all new variables
- set -o allexport
- To disable the automatic export
- set o allexport
13History
- Keeps a list of executed commands
- Allows the re-execution of commands
- Allows modification prior to re-execution
- Keeps history between sessions in
- HOME/.sh_history
14History
- history
- 121 who
- 122 ls
- ...
- 136 pwd
- history -2
- 150 vi homework
- 151 cp homework homework.bak
- 152 history -2
- history 121 124
- ...
- history 144
Displays the last 16 by default
Displays the last n the history call
Displays a range
Displays from this number to the end
15History variables
- The size of the list is specified by
- HISTSIZE100
- An alternate history file can be specified
- HISTFILE.hist
16Re-executing commands
- Last command
- r
- Last command starting with a c
- r c
- Re-executing a command using a specific history
number - r 189
17Command line editing
- Fix and re-execute the last command
- ls myfle
- myfle no such file or directory
- r flfil
- ls myfile
- myfile
- Using the history number
- r libbin 211
- /usr/bin/X11/xcalc
18Setting vi to scroll through commands
- set VISUALvior set o vi
- Use or k
- to move backward
- Use or j to move forward
- Press enter to re-execute the command
19vi to edit commands
- 0 moves to the beginning of the line
- moves to the end of the line
- l moves the cursor to the right
- h moves the cursor to the left
- a appends after the cursor
- i inserts before the cursor
20Aliasing
- Set a new alias
- alias rmrm i
- Check for existing aliases
- alias
- Aliases can be configured in one of two files
- HOME/.profile
- HOME/ENV
21Aliasing
- Turn off aliasing for one occurrence
- \rm file
- Unset all aliases
- unalias a
- Unset a specific alias
- unalias rm
22Search order
- Alias
- Built-in command
- Functions
- Hash list
- PATH variable
23cd capabilites
- cd to previous directory
- cd -
- cd shorthand
- cd /home/lee/programs
- cd lee paty
- cd /home/paty/programs
24CDPATH variable
- export CDPATH .../
- pwd
- /home/paty
- cd bin
- /home/paty/bin
- cd etc
- /etc
- cd bin
- /bin
25Tilde ()
- cd current user is lee
- pwd
- /home/lee
- cd paty paty being a valid user
- pwd
- /home/paty
- cd /bin a directory under lees
home - pwd
- /home/lee/bin
26Filename expansion
- Set
- VISUALvi
- or
- set o vi
- Type the partial name and then use thesequence
\ - For a list of options, use
27I/O redirection
- Input and output redirection is standard across
shells - ls l list
- ls l list
- sort
28Standard error
- Write the errors to a file
- find / -name test 2 error-file
- Write the errors to a terminal
- find / -name test 2 /dev/pts/130
- Throw away the errors
- find / -name test 2 /dev/null
29Standard output and standard error
- To different files
- find / -name test results 2 errors
- To the same file
- find / -name test results 21
30ksh configuration files
- /etc/default/login
- Configures basic settings for all users (path,
umask) - /etc/profile
- Configures basic settings for all ksh users
(PATH, umask, mail) - HOME/.profile
- Configures settings for each new ksh (set calls)
if it exists. Analogous to .login in csh - HOME/ENV
- Configures settings for Korn shell once at login
(alias, history, prompt). Analogous to .cshrc
31C-Shell
- Developed by Bill Joy at U.C. Berkeley
- Same functionality and programming constructs of
Bourne Shell, different keywords - First shell focused on interactivity
32csh vs sh
- csh Added
- command aliasing
- command history
- command editing
- job control
33running C-Shell
- C-shell was created as the default user shell
in some versions of Unix (now bash holds that
title) - In order to run a csh you type it in the command
line - csh
-
34csh local variables
- To set the value
- set prompthostname -s
- set noclobber
- set var1var2
- set path (path /usr/bin)
35csh local variables
- To list local variables
- set
- To unset a variable
- unset noclobber
36csh environment variables
- To set the value of an environment variable
- setenv DISPLAY 139.1.2.30.0
- List variables and their values
- env
- printenv
- Unset a variable
- unsetenv DISPLAY
- Note No equal sign is necessary (common error)
37csh predefined variables
- System-defined local variables
- Some need to be enabled, others need a value
- Enable filename completion
- set filec
- Store the last 50 commands
- set history50
38History
- csh history can be used to
- Re-execute previous commands with or without
changes - Reduce the amount of keystrokes
- To enable history we simply assign a value
- set history50
39History
- When we logout, history is lost
- To keep all or a portion of it
- set savehist50
- History is between sessions is kept in
- HOME/.history
40How to use history
- Can view portions of the list
- To view the last 3 commands
- history 3
- 96 ls
- 97 who
- 98 pwd
41Re-execute the last command
!!
!-2
Re-execute the second tothe last command
!97
Re-execute the command at entry 97 in the history
!cd
Re-execute the last commandstarting with cd
42Command line editing
- ls myfle
- myfle no such file or directory
- flfil
- ls myfile
- myfile
43Alias command
- An alias is an alternative name (usually shorter)
to - Create customized commands
- Execute multiple commands with fewer keystrokes
- Speed up commonly executed tasks
44Alias syntax
- Creating an alias Disabling alias once
- alias rm rm i \rm
- Displaying existing aliases
- alias
- rm (rm i)
- Eliminating a specific alias
- unalias rm
- Eliminating all aliases
- unalias
45Search order
- Aliases
- Built-in commands
- Hash list (list of previous path searches)
- Path
46Using History with alias
- History events fields are separated by white
space - 98 cp r project1/status /usr/martha/status
- You can use this field numbering scheme to create
an alias with user arguments. - alias loc find \!2 name \!1
0 1 2
3
47The special character
- An abbreviation of a users home directory
- It is used in one of two ways
- Change to joes home directory
- cd joe
- Change to the home directory of the account used
for login - cd
48Filename Completion
- To enable filename completion
- set filec
- Filename completion allows the C shell to
complete the name of a file or directory - Use the ESC key for name completion
- Attempts to match the unique character pattern
provided by the user - Use Ctrl-D when signals a non-unique
pattern.
49C-shell Special characters
- works as an abbreviation
- chmod ugo-w proj1,12/goals
- Instead of
- chmod ugo-w proj1/goals proj12/goals
50Redirecting Standard Input and Output
- Standard across shells
- mail bob
- cat file1 file2 file3 files
- cat file4 files
51clobbering
- Redirecting the output to an existing file
destroys (clobbers) the contents of the file - Use to append information
- Set the noclobber local variable to prevent
accidental clobbering - set noclobber
- cat memo1 memo2 memo3 files
- Files File exists
- Use the ! Symbol override noclobber
- cat header file1 ! files
52Redirecting Standard Error
- Send both output and errors to the same file
- find / -name letter /find.out
- Send standard output and errors to different
files - (find / -name letter /find.out) find.errs
53Redirecting Standard Error
- Send the output to the terminal screen (window),
and errors to /dev/null - (ls -R /dev/tty) /dev/null
- Send the output to find.out and errors to the
"bit bucket" - (find / -name letter /find.out) /dev/null
54C Shell Configuration Files
- /etc/default/login
- Configures basic settings for all users (path,
umask) - /etc/cshrc
- Configures basic settings for all C shell users
(motd, mail) - HOME/.cshrc
- Configures settings for each new C shell (alias,
history, prompt) - HOME/.login
- Configures settings for C-shell once at login
(environment variables, i.e DISPLAY)