The Terminal

The Terminal application is the gateway to the BeOS shell. For those used to a windowed environment, the use of the command line interface (CLI) takes a bit of getting used to. This section is a brief introductory tutorial. For a more in depth introduction, the BeOS Bible has an excellent section. Also highly recommended is Learning the Bash Shell by O'Reilly Associates. Wonderful though the Internet is, there's no substitute for a good book!


The Terminal Application


Like many BeOS applications, the Terminal can have about as many sessions open as you like, with each session running independently of the others. It also has some features unique to the BeOS of which more later.


What it's for


Terminal opens a window into the BeOS shell. In computer speak, a shell is the interactive interface with the operating system. The BeOS shell is based around a shell developed for Unix systems called bash. The shell is actually independant of the core operating sytem, or kernel. For this reason, many Unix-type scripts will run quite happily on the BeOS, and vice versa. Other shells can also run on BeOS, such as tc. Bash is one of the easiest to learn though, and extremely powerful, especially when it comes to scripting. Don't get confused into thinking that BeOS is somehow Unix based though because it's not. The commands used are broadly the same, but it is a different system altogether.


Navigation


The first thing to learn is how to get around. It's important to have at least an outline knowledge of the directory structure, which can be found here.


By default, the Terminal always opens up in the /boot/home directory. To test this, enter pwd (print working directory) at the prompt and press Enter. The result will be


$ pwd
/boot/home
$


Now let's see what's in the directory. Type ls (list) and then hit Enter. You will see a list of all files in your home directory. All, that is, except the hidden ones. These are files whose names begin with a '.' . If you want to see those too, the ls command needs to be modified using a 'flag', which is similar to a 'switch' in DOS. To see all files in a directory, use the -a flag like this


$ ls -a

Don't forget to type a space between ls and -a


This still doesn't tell you very much. If you want to see which files are directories, which are programs and which are other files, use the -F flag as well


$ ls -aF


All executables will be marked with a '*' and all directories with a '/'


Full information about files can be obtained with the -l (long) flag thus


$ ls -l


This gives the long description of a file. Try it and see what happens!

What you're getting here is a full listing of file attributes.


Now to change directory.


If you enter


$ cd /


The result will be to change your location to the boot directory. This is right at the top of the directory tree. In Linux it's known as 'root', and in Windows/DOS it's the C:\> prompt.


PLay with the pwd and ls commands again to have a look around, and then return to the home directory. The long way round is to enter


$ cd /boot/home


The quick way is


$ cd ~


Wherever you are in the file system, you can always get back to home with cd ~


If you get tired of typing the same commands over and over again just play with the up and down arrows. This will flip through the history of the commands you've entered. Just select which one you need. Similar to the doskey option for the old DOS users out there.


The other navigation command you need to know at this stage is cd ..


This takes you to the parent directory of wherever you are. A little attention is needed here. There has to be a space before the dots. If you're used to DOS this is a very easy mistake to make, and it really does take some time getting used to it!

File Management


File management in the shell is a little tricky. Be careful what you do. If you delete a file here, it's gone forever.


Make sure you are in the home directory. First, lets make a new directory with the mkdir (make directory) command


$ mkdir test


Now cd to that directory


$ cd test


Now to create a file. There are a number of ways to do this, but we'll be using the touch command for now


$ touch testtext.txt


If you open up your home directory then the test directory, you'll see the file you just created. Double click to open it with Styled Edit and enter some text. Save it and close it.


Back in Terminal. You can use several commands to view the contents of the file. One of the most common is cat ( concatenate )


$ cat testtext.txt


The contents of the file will be printed to the screen. If it's a long file, you may only want to view the first few lines. Try using the head command for this. To view the end of a file, use tail.

Now to reverse it all.


Deleting Files and Directories

To delete a file use the rm (remove) command thus

$ rm testtext.txt

Poof! It's gone.

now enter cd .. to go to the parent directory and enter

$ rmdir test

If the directory isn't empty you'll get an error message telling you the directory isn't empty.

Applications


The Terminal can be used to launch any application. Try the following


$ cd /boot/demos


$ Stars


The Stars demo will start.




You will have noticed that control passes to the Stars window, so click on the Terminal window again to get control. There is now a flashing cursor instead of a prompt.


To close Stars hold down the Ctrl key and press C.


*Note - a common convention for notating the Ctrl key is '^' e.g. ^C, which is used from now on.


Now for some mulitasking. Supposing you want to start another app whilst Stars is running? Well, one way is to open another Terminal by opening from the Be menu, choosing New Terminal from the Terminal menu, or by tapping Alt and N together. This starts to get awkward of course, with two windows open for every application. What we can do is assign it to the background using the '&' symbol. Try this


$ Stars &


The result will be something like this


$ Stars &
5348
$


The number that comes up is the process id the shell has just assigned to the task. You can now proceed to open other programs. Try this


$ GL Teapot &
$ Stars &
$ Kaleidoscope &


Now sit back and enjoy the view!


Ok, now suppossing you wanted to do something like this but you don't want to type commands all the time? This can be done a couple of ways. Here's where you get a very brief introduction to scripts.


Scripts


If you're coming from DOS, then think of scripts as being similar to batch files. A script is a collection of commands that the shell can recognise and act upon. By convention they normally have the extension '.sh'. The BeOS doesn't actually rely on extensions to be able to interpret type of file, but the extension is used as a reference for people. Naming files is covered later.


Open up Styled Edit and enter this.


#! /bin/sh


cd /boot/demos


Stars &
Kaleidoscope &
GLTeapot &


Save it in your home directory as demo.sh


The first line tells the shell that this file is a script and calls the shell binary file i.e. it starts the script. The following lines should be self explanatory by now.


Change back to your home directory, and just enter demo.sh.


Scripting gets much, much more complex than this of course, but users of all levels can make use of it to some degree or another. The more you get into the idea of scripting, the more you will appreciate it's power on the BeOS.

A WORD OF WARNING!! Although there are as yet no reports yet of viruses that affect the BeOS, it is certainly possible to write extremely dangerous scripts. For example, a Linux user I knew was unfortunate enough to run a script sent by a 'friend' that immediately filled his hard disk. It is also very easy to run commands that will wipe your disk, or clobber system files. To lessen your chances of utter disaster, always observe the following rules:

1. Never run a script sent to you until you have at least had a look at it.

2. If in any doubt about the origins or functions of the script, do not run it.

3. Always be sure you check what you're doing when writing your own scripts or shell commands.

4. Always read any instructions that come with a script to the letter.

 

In the next tutorial, we'll be looking at some more complex shell commands, including those that are unique to the BeOS.