FIX: manpage links
[ikiwiki.git] / docs / handbook / handbook-shells.mdwn
1 \r
2 ## Shells \r
3 \r
4 In DragonFly, a lot of everyday work is done in a command line interface called a shell. A shell's main job is to take commands from the input channel and execute them. A lot of shells also have built in functions to help everyday tasks such as file management, file globbing, command line editing, command macros, and environment variables. DragonFly comes with a set of shells, such as `sh`, the Bourne Shell, and `tcsh`, the improved C-shell. Many other shells are available from pkgsrc®, such as `zsh` and `bash`.\r
5 \r
6 Which shell do you use? It is really a matter of taste. If you are a C programmer you might feel more comfortable with a C-like shell such as `tcsh`. If you have come from Linux or are new to a UNIX® command line interface you might try `bash`. The point is that each shell has unique properties that may or may not work with your preferred working environment, and that you have a choice of what shell to use.\r
7 \r
8 One common feature in a shell is filename completion. Given the typing of the first few letters of a command or filename, you can usually have the shell automatically complete the rest of the command or filename by hitting the  **Tab**  key on the keyboard. Here is an example. Suppose you have two files called `foobar` and `foo.bar`. You want to delete `foo.bar`. So what you would type on the keyboard is: `rm fo[ **Tab** ].[ **Tab** ]`.\r
9 \r
10 The shell would print out `rm foo[BEEP].bar`.\r
11 \r
12 The [BEEP] is the console bell, which is the shell telling me it was unable to totally complete the filename because there is more than one match. Both `foobar` and `foo.bar` start with `fo`, but it was able to complete to `foo`. If you type in `.`, then hit  **Tab**  again, the shell would be able to fill in the rest of the filename for you.\r
13 \r
14 Another feature of the shell is the use of environment variables. Environment variables are a variable key pair stored in the shell's environment space. This space can be read by any program invoked by the shell, and thus contains a lot of program configuration. Here is a list of common environment variables and what they mean:\r
15 \r
16 [[!table  data="""
17 |<tablestyle="width:100%"> Variable | Description 
18 <tablestyle="width:100%"> `USER` | Current logged in user's name. 
19  `PATH` | Colon separated list of directories to search for binaries. 
20  `DISPLAY` | Network name of the X11 display to connect to, if available. 
21  `SHELL` | The current shell. 
22  `TERM` | The name of the user's terminal. Used to determine the capabilities of the terminal. 
23  `TERMCAP` | Database entry of the terminal escape codes to perform various terminal functions. 
24  `OSTYPE` | Type of operating system. e.g., DragonFly. 
25  `MACHTYPE` | The CPU architecture that the system is running on. 
26  `EDITOR` | The user's preferred text editor. 
27  `PAGER` | The user's preferred text pager. 
28  `MANPATH` | Colon separated list of directories to search for manual pages. |\r
29 """]]\r
30 Setting an environment variable differs somewhat from shell to shell. For example, in the C-Style shells such as `tcsh` and `csh`, you would use `setenv` to set environment variables. Under Bourne shells such as `sh` and `bash`, you would use `export` to set your current environment variables. For example, to set or modify the `EDITOR` environment variable, under `csh` or `tcsh` a command like this would set `EDITOR` to `/usr/pkg/bin/emacs`:\r
31 \r
32     \r
33     % setenv EDITOR /usr/pkg/bin/emacs\r
34 \r
35 \r
36 Under Bourne shells:\r
37 \r
38     \r
39     % export EDITOR="/usr/pkg/bin/emacs"\r
40 \r
41 \r
42 You can also make most shells expand the environment variable by placing a `$` character in front of it on the command line. For example, `echo $TERM` would print out whatever `$TERM` is set to, because the shell expands `$TERM` and passes it on to `echo`.\r
43 \r
44 Shells treat a lot of special characters, called meta-characters as special representations of data. The most common one is the `*` character, which represents any number of characters in a filename. These special meta-characters can be used to do filename globbing. For example, typing in `echo *` is almost the same as typing in `ls` because the shell takes all the files that match `*` and puts them on the command line for `echo` to see.\r
45 \r
46 To prevent the shell from interpreting these special characters, they can be escaped from the shell by putting a backslash (`\`) character in front of them. `echo $TERM` prints whatever your terminal is set to. `echo \$TERM` prints `$TERM` as is.\r
47 \r
48 ### Changing Your Shell \r
49 \r
50 The easiest way to change your shell is to use the `chsh` command. Running `chsh` will place you into the editor that is in your `EDITOR` environment variable; if it is not set, you will be placed in `vi`. Change the ***Shell:*** line accordingly.\r
51 \r
52 You can also give `chsh` the `-s` option; this will set your shell for you, without requiring you to enter an editor. For example, if you wanted to change your shell to `bash`, the following should do the trick:\r
53 \r
54     \r
55     % chsh -s /usr/pkg/bin/bash\r
56 \r
57 \r
58  **Note:** The shell that you wish to use ***must*** be present in the `/etc/shells` file. If you have installed a shell from the [ pkgsrc tree ](pkgsrc.html), then this should have been done for you already. If you installed the shell by hand, you must do this.\r
59 \r
60 For example, if you installed `bash` by hand and placed it into `/usr/local/bin`, you would want to:\r
61 \r
62     \r
63     # echo "/usr/local/bin/bash" >> /etc/shells\r
64 \r
65 \r
66 Then rerun `chsh`.\r