TOC PREV NEXT INDEX

QNX Logo


8 Using the Command Line Interface

This chapter covers the following topics:

Introduction

When you installed RTP, you were given the option of booting to Photon or the command line. The default is to Photon so unless you chose otherwise Photon starts automatically when you boot. If you want to change this option so you can start in command-line mode instead of Photon, see the note in "Selecting command-line or GUI".

Photon provides you with an easy-to-use RTP interface (see "Using the Graphical User Interface"), but many people prefer to work with command lines and this chapter is for those people. If you want to use command lines from Photon, you can start a terminal by clicking on the Terminal icon on the Photon shelf (located at the edge of your workspace). You can start several terminals at once if you wish, each capable of running multi-tasking processes.

If you are already familiar with QNX, it still might be worthwhile scanning this chapter: there are some differences between QNX 6, our latest OS used in this RTP, and our older QNX OS. (If you are migrating from QNX4 to QNX 6, these differences are covered in greater detail in the migration guide available when you install the migration software from the repository: see "Migrating from QNX4 to QNX6".

If you are new to QNX, this chapter will help you get started using QNX 6 command lines.

For additional information on the utilities that control QNX RTP consoles, see the following topics in the QNX 6 Utilities Reference:

To find out about:
refer to this command:
simple console and keyboard I/O managers
devc-con; devc-tcon (x86 only)
command interpreter
sh
setting tty attributes
stty

[Author's Comments: explain how to launch a shell script within pterm when the pterm is started Are there any Pterm menus? Explain commands)]

Keyboard basics

This section describes the standard console and keyboard conventions used when you are working with command lines.

Some keys may behave differently from how they are described here, depending on how you configure your system.

This section covers the following topics:

Entering line-oriented input

[Author's Comments: add an intro here]

Line-editing keys

There are two modes you can use for keyboard entry: raw input mode and edited input mode. The difference is that in raw input mode each character is submitted to an application process as it is received whereas in edited input mode, the application process receives characters only after a whole line has been entered (usually signalled by a CR).

For more information on raw input mode and edited input mode, see System Architecture.

The QNX 6 shell has additional input editing commands (for more information, see sh in Utilities Reference).
Note also that your keyboard may not behave as indicated if:
  • you are working with an application that has complex requirements for user interaction (the application may take control over how the keyboard works), or
  • you are working at an attached terminal (the terminal may have keyboard limitations).

Recalling commands

The shell lets you recall commands that you've previously entered, then re-execute them. These commands are maintained by the shell in a buffer: use the up- and down-arrow keys to move through the buffer and then press Enter when you see the command you want to re-execute.

Switching virtual consoles

The display adapter, the screen, and the system keyboard are collectively referred to as the console. To let you interact with several applications at once, QNX 6 permits multiple sessions to be run concurrently on consoles by means of virtual consoles. These virtual consoles are usually named /dev/con1, /dev/con2, etc.

Each virtual console can be running a different foreground application that uses the entire screen. The keyboard is attached to the virtual console that's currently visible. As long as Photon is not running and the consoles were set up using tinit, you can switch from one virtual console to another, and thus from one application to another, by entering these keychords:

If you want to see:
Press:
the next active console
Ctrl-Alt-Enter
or
Ctrl -Alt-+
the previous active console
Crtl-Alt--


The + (plus) and - (minus) keys used in the console-switching keychords are those on the numeric keypad.

You can also jump to a specific console by using typing

Ctrl-Alt--n

Where n is a numeric digit that represents the console number of a virtual console. For instance:

If you want to see:
Press:
/dev/con1
Crtl-Alt-1
/dev/con2 (if available)
Crtl-Alt-2
...
...
/dev/con4 (if available)
Crtl-Alt-4


You can have up to 9 virtual consoles, but the default maximum number is 4; if you need to increase this number, use the -n option of devc-con or devc-tcon (see Utilities Reference)

For more information on the QNX 6 console, see devc-con in Utilities Reference and the Console devices section of System Architecture.

Using multiple consoles

As root, you can specify how many virtual consoles are supported on a machine by specifying an argument to the console driver process when it is started (see the -n option of devc-con in Utilities Reference).

The administrator can also specify the program, if any, that is initially launched on each console. By default, the terminal initialization utility (tinit in Utilities Reference) launches a login command on the first console only, but will be "armed" to launch a login on any other console on which you press a key. This means that while console 1 is always available, any other given console won't be used unless you specifically switch to that console and press a key.

To start a login on an unused console, switch to the unused console by pressing

Ctrl-Alt-n

where n is a number (1-9), and then press any key.

You can now access the console using any of the cyclical console-switching keychords described in "Switching virtual consoles," (the previous section).

When you terminate the session by typing logout or exit, or by pressing

Ctrl-D

the console will once again be idle. It won't appear when you use any of the cyclical console-switching keychords. The exception is console 1, on which the system usually restarts a login.

Changing the console fonts

[Author's Comments: Is this supported? How do we inform the driver about new fonts or to redefine existing fonts to provide fonts of different sizes or fonts that contain alternate character sets in Nto?]

Killing a process

If you need to kill the process currently running on the console, press

Ctrl-C

or

Ctrl-Break

Invoking the system debugger

[Author's Comments: user query: Does QNX RTP come with a low-level system debugger that lets you set breakpoints in programs, display and edit memory, disassemble code, and examine I/O ports? If so, how do you invoke and use it?)]

Rebooting

The root user may shut down and reboot a system by typing shutdown. This utility has several options allowing you to name the node to shut down (default is the current node), specify the type of shut down (default is reboot), shut down quickly, or list the actions taken during the shut down (verbose), see shutdown in the Utilities Reference for more information.

International keyboards

Some keyboard layouts - the French and German layouts, for example - use accent keys which, by themselves, don't generate a character. QNX 6 treats these keys as "dead" keys. Pressing a dead key, followed by a second key, modifies the second key, creating an accented character. For example, to create the Ü character, you press " followed by

Shift-U

[Author's Comments: check this out on German and French keyboards - it may need to be shift-] then shift-U instead]

This dead key processing provides typists with a familiar method of composing characters.


You can also generate composed characters by pressing and releasing Alt followed by two characters, e.g. pressing and releasing the characters Alt " U results in Ü.

Remapping the keyboard layout

[Author's Comments: user query: @@how I can remap the keyboard? Is there a dvorak remapper for qnx RTP, ...and Hungarian etc.) Is there a localization app?]

The keyboard at a glance

If you want to:
Press:
Move the cursor to the left
left-arrow
Move the cursor to the right
right-arrow
Move the cursor to the start of a line
Home
Move the cursor to the end of a line
End
Delete the character left of the cursor
Backspace
Delete the character at the cursor
Del
Delete all characters on a line
Ctrl-U
Toggle between insert and typeover modes (where an application provides)
Ins
Submit a line of input or start a new line
Enter
Recall a command
up- or down-arrow
Switch to the next virtual console
Ctrl-Alt-Enter
or
Ctrl-Alt-+
(+ on number keypad)
Switch to the previous virtual console
Ctrl-Alt--
(- on number keypad)
Switch to a specific virtual console
Ctrl-Alt-n
Suspend display of output
Ctrl-S
Resume display of output
Ctrl-Q
Attempt to kill a process
Ctrl-C
or
Ctrl-Break
Break Indicate end of input (EOF)
Ctrl-D

Command basics

This section tells you about the command structure you will be using when working in command-line mode.


To learn more about the Korn shell command interpreter, see ksh in the Utilities Reference.

This section covers the following topics:

Understanding command syntax

Whenever you look up a command in the Utilities Reference, you'll see a syntax statement that summarizes how the command can be used. For most commands, this statement consists of three main parts:

command_name options operands

Where:

command_name

is the name of the command to be executed. This may be the name of an executable program, such as a utility, or it may be the name of a command built into the shell.

options

specify an alternate behavior for the command. Options typically consist of an alphanumeric character preceded by a dash (e.g. -c). Some options take an argument (e.g. -n number). If you specify an option that takes an argument, you must include its argument as well.

operands

specify the data the command requires (typically a filename). If a command lets you enter multiple operands, they are usually processed in the order you list them. Unlike options, operands aren't preceded by a hyphen (e.g. file...).

For instance, the syntax description for more in the Utilities Reference, is given as follows:

more [-ceisu] [-n number] [-p pattern]
    [-/ pattern] [-t tag] [-x tabstop] [file...]

If you enter multiple options, you only have to enter one hyphen at the start of the option list. The option line: [-ceisu] is simply an economical way of indicating that the following options are available: -c -e -i -s -u
Key symbols

When reading a syntax statement, you should be aware of these symbols:

This symbol:
indicates this:
....
An ellipsis following an option argument or an operand indicates that more than one can be specified. For example, in the more utility, the operand:
file... 
indicates that you can specify more than one file on the command line, e.g. more myfile1 myfile2
[ ]
Anything enclosed in brackets ([ ]) is optional. Options are always enclosed within brackets (e.g. [-c]). If an operand is enclosed in brackets, its use isn't mandatory (e.g [file...] in the above illustration).
|
The OR bar is used between alternatives, indicating that only one can be selected (e.g. -a|-f).

Grouping options

You can list each option separately on the command line, e.g.

more -c -e myfile

Or you can run several options together using a single dash (-), e.g.

more -ce myfile
Quoting special characters

Certain characters may have special meaning to the Shell, depending on their context. If any of the special characters recognized by the Shell are to be included in a command line, then you may have to quote these characters. Quoting refers to a method of forcing these characters to be treated as simple characters instead of being interpreted in a special way by the Shell.

You must quote the following characters to avoid their special interpretation:
|
$
(
"
)
&
`
;
\
'
<tab>
<newline>
<space>


You might need to quote the following characters, depending on their context within a shell command:

* ? [ # ~ = %

There are three methods of quoting characters:
In order to quote:
you can:
a single character
precede the character with a single backslash (\) character
all special characters within a string of characters
enclose the whole string in single quotes
all special characters within a string, except for $, `, and \
enclose the whole string in double quotes

Examples:

Any of these commands search for all occurrences of the string QNX 4 within the chapter1.txt file:

grep QNX\ 4 chapter1.txt 
grep 'QNX 4' chapter1.txt 
grep "QNX 4" chapter1.txt 

However, note that:

grep QNX 4 chapter1.txt 

wouldn't do what you might expect, as it would attempt to find the string QNX in the files named 4 and chapter1.txt.

In addition, this command:

grep 'QNX\ 4' chapter1.txt 

wouldn't search for QNX4 either, because the single quotes have caused the Shell to ignore the special meaning of the backslash character. Hence the above command would attempt to find the string:

QNX\ 4 

within the chapter1.txt file.

[Author's Comments: check this as grep processes its own special characters]

To learn more about this topic, see the Quoting section of ksh in the Utilities Reference.

Redirecting input and output

Most commands read their input from the standard input stream (stdin), which is normally assigned to your keyboard, and write their output to the standard output file (stdout), which is normally assigned to your display screen. There are occasions, however, when you want commands to:

If you want a process to:
use this symbol:
read from a file, or another device (input redirection)
<
redirect stdout to a file (output redirection)
>
redirect stdout to a file, appending to the file's contents (output append)
>>
redirect stdout directly to another command (pipe)
|

For example, let's look at the ls command, which lists the files in a directory. If you want the list of files that ls outputs to be redirected to a file called filelist, you would enter:

ls > filelist

To learn more about this topic, see the input/output redirection section of the ksh utility in Utilities Reference.

Executing commands on another node or tty

If Qnet is running, QNX 6 allows you to execute commands on a machine other than your own if both machines are on the same network this is known as remote execution.

Each machine in a network is called a node. When a command is invoked on another node, the command's standard input, standard output, and standard error output are displayed on your console screen (or terminal) unless you explicitly redirect them to another device.

For more information, see the on command in the Utilities Reference.

Displaying online usage messages

Each QNX 6 utility provides an online usage message. You display a utility's usage message with the use command. For example, to display the message for more, you would type:

use more 

The use command is the RTP equivalent of man in UNIX and Linux and man may work with utilities ported from other sources. If you request usage for a command and the command either doesn't have an executable in the current path or doesn't contain usage message records, an error message is displayed.

For more information on this command, see use in Utilities Reference.

Using wildcards

Instead of using a command to work on just one file at a time, you can use wildcards to perform operations on several files at once. Directories, as well as files, are matched by these wildcards:

If you want to:
use this wildcard:
match zero or more characters
*
match any single character
?
match any characters (or range of characters separated by a dash) specified within the brackets
[]
exclude characters specified within brackets
!


Hidden files, i.e. files whose names start with a dot (e.g. .profile), are not matched unless you specify the dot. E.g. typing * does not match .profile, but .* does.

Examples

The following examples show you how you can use wildcards with the cp utility to copy groups of files to a directory named /tmp (for more information on using cp, see the Utilities Reference).

If you enter:
cp does this
cp f* /tmp  
copies all files starting with f (e.g.frd.c, flnt)
cp fred? /tmp
copies all files beginning with fred and ending with one other character (e.g. freda, fred3)
cp fred[123] /tmp
copies all files beginning with fred and ending with 1, 2, or 3 (i.e. fred1, fred2, and fred3)
cp *.[ch] /tmp 
copies all files ending with .c or .h (e.g.frd.c, barn.h)
cp *.[!o] /tmp	 
copies all files that don't end with .o
cp *.{html,tex} 
copies all files that end with .html or .tex

Entering multiple commands

You can enter more than one command at a time by separating your commands with a semicolon (;). For example, if you want to determine your currently working directory you would type pwd, and then if you wanted to see what it contains, you would type ls. Or you could combine the two commands as follows:

pwd;ls 

Or let's say you want to make a copy of a file in your current working directory, then see the directory's updated contents. You could enter something like this:

cp myfile myfile2;ls 

A note on shell scripts

You can enter any number of shell commands into a text file and then invoke the commands in batch mode simply by executing (or shelling) the file. A file containing shell commands is commonly known as a shell script. You can execute a shell script in either of two ways:


QNX Software Systems Ltd.
http://www.qnx.com
Voice: +1 613 591 0931
Fax: +1 613 591 3579
info@qnx.com
TOC PREV NEXT INDEX