Glindra
Documentation Index Download
Command Line File Handling and ASCII Tools

Parameters and Options

Parameters

With most commands, you can provide additional information to the command by giving various parameters and options. The d directory command, for instance, takes a file specification as a parameter, and will only list those files that match the specification. Thus

> d '*.txt'
will list all files that have a .txt extension, and only those.

The single quotes around *.txt are required under Linux, to prevent the shell from expanding the * wildcard into a list of filenames ("globbing"). Under Windows, the single quotes in this example are legal but unnecessary.

The cop command, which is used to copy files, takes two parameters: an input file specification and an output file specification. For example, the command

> cop '*.txt' '*.doc'
will make copies of all files that have the extension .txt, and give each of the copied files the extension .doc, in the same way as the Windows copy command would.

Again, the single quotes around the filenames with wildcards are not required under Windows.

Filenames that contain space characters must be enclosed in either single or double quotes under both Windows and Linux.

Quoted Strings

Under Linux, filenames that contain any of the wildard characters *?[] must be enclosed in quotes, to prevent the shell from globbing them. Use either " or ' to quote each such filename.

Under both Windows and Linux, filenames and other strings that contain blanks must be enclosed in quotes. To preserve multiple adjacent blanks under Windows, the " quote character must be used. Under Linux, both " and ' work the same in this respect.

This also applies for strings that contain other special characters that would normally be interpreted by either the shell (bash or Windows), or the Glindra command line parser. Examples of such characters are ()=\/<|> and others, depending on the context.

In complicated cases, where a string contains characters that have special meanings to the shell and/or to the Glindra command line parser, it may be necessary to enclose the string in both single and double quotes.

Example (Windows and Linux)
Suppose we want to find all lines in a file that contain a dot, two blanks, and a lower case letter. The regular expression for expressing this is \. [a-z] (with two space characters in the middle).

To find all such strings in a file, we can use the following command under both Windows and Linux:

> se -regex -exact a.txt '"\.  [a-z]"'
Under Windows, the shell will interpret the " quote characters and make sure the two adjacent blanks in the string are preserved, and the Glindra command line parser will use the ' quotes to determine where the string begins and ends.

Under Linux, the bash shell will interpret the outer pair of quotes and make sure the blanks are preserved, and the Glindra command line parser will use the inner pair of quotes.

Parameter Grouping

Sometimes a parameter or an option value may be a list of several items. One example of this is commands that take multiple input files as a parameter, such as cop and rena. Instead of just giving a single file specification as the first parameter, you can give a list of files enclosed in parentheses ().

Example (Windows)
> rena (a.doc b.doc c.doc) *.txt
will rename each of the files a.doc, b.doc, and c.doc by changing the extension to .txt.

Under Linux, the parentheses must be prefixed by an escape character to keep the shell from reacting on them.

Example (Linux)
> rena \(a.doc b.doc c.doc\) '*.txt'
The escape character under Linux is backslash.


A group within parentheses continues up to the first balanced left parenthesis that is not within single or double quotes. Parentheses may be nested to an arbitrary depth.

Parentheses vs. quotes

There is a difference between parameters grouped with parentheses, and the quoted strings discussed earlier. The command

> rena "bing bang bong.doc" *.txt
will change the extension of a single file called bing bang bong.doc.

The command

> rena (bing bang bong.doc) *.txt
will try to rename three different files called bing (without any extension), bang, and bong.doc to bing.txt, bang.txt, and bong.txt.


If you need to give a list of filenames that each have to be placed within quotes, you must make a separate quoted string for each filename.

Example (Linux)
> rena \('*.bak' '*.doc'\) '*.txt'

Options

Option names

Start with - or -- or /

Command options can start with a dash (-), two dashes, (--), or, on Windows, a slash (/). There is no semantic difference between the three variants.

Example (Windows and Linux)
> d -files
> d --files
Example (Windows)
> d /files
These commands have exactly the same meaning.

The format with the dash (-) can be used on Windows as well. If you often switch between Unix and Windows, you can use the dash format on both systems. If you run only Windows, you may prefer using a slash (/) like in other Windows commands.

Space before -

There must be a space before options that start with a single or double dash, but this is not necessary for options that start with slash on Windows.

Example (Windows and Linux)
> d -files
> d --files
Example (Windows)
> d/files
Anywhere in the command line

Options may be placed anywhere on the command line. They may appear before, between, or after any parameters. There is no difference in meaning between these two:

> d '*.txt' -files
> d -files '*.txt'
Options can be abbreviated

Option names are normal English words written out in full. They can normally be abbreviated down to two characters, provided they remain unambiguous. The option names are not case sensitive.

Example (Windows)
> d -FILES
> d --fi
> d /FiLe


Some programs have options that can be abbreviated to a single character.

Example (Windows and Linux)
> d -o=mydir.lis

Single character options behave just like the longer options. They are not case sensitive. If there is a value associated with the option, there must be an equals sign between the option and the value.

If there are more than one single character options in a command line, you must specify each of them separately. The Unix convention of just writing the option letters together, and omitting the space and dash before each of them, is not supported.


Negated options

In order to negate the meaning of an option, you just add no to the beginning of the option name. For example, the command
> d -noheader
will produce a directory listing without headers.


Negated option names can be abbreviated just like normal options, so

> d -nohea
works just as well.

"Conflicting" options

It is not considered an error if the same option appears more than once in a command line. If there are several apparently conflicting occurrences of the same option, it is only the last one that counts. For example, the command
> d -noheader -header
would produce a directory listing with headers.

Experience (from VMS, which works in this way) shows that this is a really useful convention. In practice it proves to be far better than the alternative of aborting the command with some error message complaining about conflicting options.

The great advantage is that if you define an alias for some command with a particular set of options, you can still override these options when you need to.

Example
If the alias dbig is defined to mean d -files -size -min_size=10mb, we can override the minimum size and write
> dbig -min=20mb
This will resolve to
> d -files -size -min_size=10mb -min_size=20mb
As the first occurrence of the -min_size option is just ignored, there is no conflict, and the command will list all files that are at least 20 Mb in size.

Options with values

Many options to various commands allow you to supply one or more values.

Example (Windows and Linux)
> d -since=1-nov-2004 -o=mydir.tmp -min_size = 5mb
In this example, the first value is a date, the second is an output file name, and the third one is a size in bytes.
Single value

Options that take a single value always have the syntax

-option_name = value
The equals sign between the option name and the value is required, even for single letter options. Spaces around the equals sign are allowed but optional.

If the value itself contains special characters, such as blanks, slashes (on Windows), equals signs, or parentheses, or if it starts with a dash, it must be enclosed in quotes.

Multiple values within parentheses

Some options accept multiple values, or multiple suboptions. The syntax is:

-option_name = (value1 value2 ...)
Example (Windows)
> d -sort = (date descending)
> d -exclude=(.tmp .xyz)

Option values within parentheses are parsed recursively, as if they had been command lines of their own. For certain options, the expression within parentheses may contain various sub-options that have the same syntax as the top level options.

For example, when the value is a file specification, the file specification itself may contain options to restrict the selection of files. If some program has an option to specify a single parameter file, writing

-parameter_file=(myfile.par -before=30-may)
would instruct the program to use the highest version of the file myfile.par that was created before May 30.
Escape character needed under Linux

The standard Linux shells have a special meaning for parentheses, so you will have to use a backslash \ as escape character before each left or right parentheses.

Example (Linux)
> d -sort = \(date descending\)