Knowledge Base/Unix/General

 

From Quantitative Finance

Jump to: navigation, search

Contents

Finding out which shell you are using

Inspect the SHELL environment variable. The command

echo $SHELL

will display its value. Look at the last part of the pathname:

  • /bin/sh - Bourne shell
  • /bin/bash - Bourne Again SHell
  • /bin/csh - C shell
  • /bin/ksh - Korn shell
  • /bin/tcsh - TC shell
  • /bin/zsh - Z shell

Which shell is best for me?

The following has been reproduced from unix-faq/shell/shell-differences ver. 1.17:

Feature sh csh ksh bash tcsh zsh rc es
Job control N Y Y Y Y Y N N
Aliases N Y Y Y Y Y N N
Shell functions Y(1) N Y Y N Y Y Y
"Sensible" Input/Output redirection Y N Y Y N Y Y Y
Directory stack N Y Y Y Y Y F F
Command history N Y Y Y Y Y L L
Command line editing N N Y Y Y Y L L
Vi Command line editing N N Y Y Y(3) Y L L
Emacs Command line editing N N Y Y Y Y L L
Rebindable Command line editing N N N Y Y Y L L
User name look up N Y Y Y Y Y L L
Login/Logout watching N N N N Y Y F F
Filename completion N Y(1) Y Y Y Y L L
Username completion N Y(2) Y Y Y Y L L
Hostname completion N Y(2) Y Y Y Y L L
History completion N N N Y Y Y L L
Fully programmable Completion N N N N Y Y N N
Mh Mailbox completion N N N N(4) N(6) N(6) N N
Co Processes N N Y N N Y N N
Builtin artithmetic evaluation N Y Y Y Y Y N N
Can follow symbolic links invisibly N N Y Y Y Y N N
Periodic command execution N N N N Y Y N N
Custom Prompt (easily) N N Y Y Y Y Y Y
Sun Keyboard Hack N N N N N Y N N
Spelling Correction N N N N Y Y N N
Process Substitution N N N Y(2) N Y Y Y
Underlying Syntax sh csh sh sh csh sh rc rc
Freely Available N N N(5) Y Y Y Y Y
Checks Mailbox N Y Y Y Y Y F F
Tty Sanity Checking N N N N Y Y N N
Can cope with large argument lists Y N Y Y Y Y Y Y
Has non-interactive startup file N Y Y(7) Y(7) Y Y N N
Has non-login startup file N Y Y(7) Y Y Y N N
Can avoid user startup files N Y N Y N Y Y Y
Can specify startup file N N Y Y N N N N
Low level command redefinition N N N N N N N Y
Has anonymous functions N N N N N N Y Y
List Variables N Y Y N Y Y Y Y
Full signal trap handling Y N Y Y N Y Y Y
File no clobber ability N Y Y Y Y Y N F
Local variables N N Y Y N Y Y Y
Lexically scoped variables N N N N N N N Y
Exceptions N N N N N N N Y

Key to the table above

  • Y - Feature can be done using this shell.
  • N - Feature is not present in the shell.
  • F - Feature can only be done by using the shells function mechanism.
  • L - The readline library must be linked into the shell to enable this Feature.

Notes to the table above

  1. This feature was not in the orginal version, but has since become almost standard.
  2. This feature is fairly new and so is often not found on many versions of the shell, it is gradually making its way into standard distribution.
  3. The Vi emulation of this shell is thought by many to be incomplete.
  4. This feature is not standard but unoffical patches exist to perform this.
  5. A version called 'pdksh' is freely available, but does not have the full functionality of the AT&T version.
  6. This can be done via the shells programmable completion mechanism.
  7. Only by specifing a file via the ENV environment variable.

Customising your working environment

When you log into the system, it runs the system profile file, /etc/profile. Usually this file is readable by all users, writable exclusively by the administrator.

After the system profile, the user profile file(s) is/are run from the user's home directory. These are shell-specific. They are essentially shell scripts that you can edit to customise your environment, e.g. set the environment variables. Here is a list of user profile scripts for different shells:

  • Bourne shell: .profile
  • Bourne Again SHell: .bash_profile
  • C shell: .login and .cshrc
  • Korn shell: .profile
  • TC shell: .login, .tcshrc and .cshrc
  • Z shell: .zlogin and .zshrc

What's the difference between the multiple user profile files?

.cshrc (.tcshrc, .zshrc) is executed when the user first logs into the system and each time a sub shell is spawned (a shell script is executed).

TC shell looks for .tcshrc first. If one is not found, it looks for and executes .cshrc.

.login (.zlogin) is executed when the user logs into the system immediately after .cshrc (.tcshrc, .zshrc). However, it is not executed when a sub shell is spawned.

.login (.zlogin) should contain commands which only need to happen at login time, not for ach shell invocation. Thus it would be a bad idea to redefine your path variable in .login (.zlogin) and not in .cshrc (.tcshrc, .zshrc) because sub shells (including X Windows other than your initial login window) would not be aware of this new path.

In general, you will customise .cshrc for C shell, .tcshrc for TC shell, .zshrc for Z shell.

Notes

  1. C shell and TC shell will also run /etc/csh.cshrc, /etc/csh.login at login and /etc/csh.logout. These are likewise global (affect all users) and are edited by the administrator.
  2. Such "dot"-files are not normally displayed by ls. To view them, you should use
ls -la

Finding out which groups a given user belongs to

The command is groups [ user ... ]. To discover your own group membership, simply enter

groups
 
 
Google
 
Personal tools