UnixDos Argument Expansion 

The "argument expansion" allows you to specify an entire group of files instead of having to type each individual filename on the command line.

Introduction

You have the following three files in the current directory 'do_arg.c', 'more.c' and 'wc.c'.
To copy all these to the '/tmp' directory you have to type:

cp do_arg.c more.c wc.c /tmp

UnixDos,Toolkit,utilities,file,management,administration,command,line,process,control,batch,UNIX,Windows95,WindowsNT,UnixDos,Toolkit,conversion,edit,manipulation,search,directory,count,extract,sort,split,compare,merge,test,interaction,MSDOS,DOS,32bit,16bit,grep, ls, du, df, find, mv, rm, m4,chmod, cc, dd, cmpdir, cut, cpio, expr, head, tail, fgrep, egrep, mkdir, mvdir, nl, paste, pr, od, rm, sed, sleep, split, sum, strings, tee, touch, date, echo, join, more, uniq, sort, uptime, uudecode, uuencode, wc, which,sharewareYou can imagine this can be very tedious and error prone, so more than 20 years ago when the UNIX environment was built the "argument expansion" was introduced. So now you can just type:

cp *.c /tmp

And '*.c' will be "expanded" to the list of all files ending with '.c'.

In UNIX this "expansion" job is centrally done automatically for you no matter which utility you use at the command line (from the "Shell" which surrounds the operating system like the shell in the sea surrounds a pearl).

UnixDos,Toolkit,utilities,file,management,administration,command,line,process,control,batch,UNIX,Windows95,WindowsNT,UnixDos,Toolkit,conversion,edit,manipulation,search,directory,count,extract,sort,split,compare,merge,test,interaction,MSDOS,DOS,32bit,16bit,grep, ls, du, df, find, mv, rm, m4,chmod, cc, dd, cmpdir, cut, cpio, expr, head, tail, fgrep, egrep, mkdir, mvdir, nl, paste, pr, od, rm, sed, sleep, split, sum, strings, tee, touch, date, echo, join, more, uniq, sort, uptime, uudecode, uuencode, wc, which,sharewareIn DOS the command line is completely "dead" because the "shell" (command.com) does not do any expansion, only some internal commands have a very limited "expansion" inbuilt (DIR, COPY, etc...).

To fill this gap we included in all individual UnixDos utilities the full "expansion" logic, so that you don't have to remember which utility has expansion and which not and you don't need any installation like in other products (MKS).

The most powerful argument expansion can (still) be found in the UNIX environment, while DOS is still very primitive.

Example:

To copy your C sources and include files in DOS you have to type two separate commands:

copy *.c A:
copy *.h A:

While UNIX and UnixDos allows you to do the job in one go:

cp *.c *.h a:

You could even use a more sophisticated expression in UNIX and UnixDos (see below under Regular Expression):

cp *.[ch] a:

The UnixDos utilities provide "Regular Expression" for file matching and even more powerful features (see "UnixDos Argument Expansion Extensions").

UnixDos,Toolkit,utilities,file,management,administration,command,line,process,control,batch,UNIX,Windows95,WindowsNT,UnixDos,Toolkit,conversion,edit,manipulation,search,directory,count,extract,sort,split,compare,merge,test,interaction,MSDOS,DOS,32bit,16bit,grep, ls, du, df, find, mv, rm, m4,chmod, cc, dd, cmpdir, cut, cpio, expr, head, tail, fgrep, egrep, mkdir, mvdir, nl, paste, pr, od, rm, sed, sleep, split, sum, strings, tee, touch, date, echo, join, more, uniq, sort, uptime, uudecode, uuencode, wc, which,sharewareRegular Expression for File Matches

The UNIX/UnixDos "Regular Expression" allows you to find specific filenames.

To communicate your search criteria the following meta characters are used:

Meta or Special Characters

? Wildspace: Matches any single character.
* Wildcard: Matches any number of characters.
[...] List: Matches any single character which is part of the specified list/range.
[^...] Inverted List: Matches any single character which is NOT part of the specified list/range.
\c Escape special meaning of character 'c'

Examples:

a* matches all files starting with 'a' of any length.
*.c matches all files with the extension '.c'
?.c matches all files with a single letter filename and extension ".c"
??.c matches all files starting with exactly 2 characters and extension '.c'
*.?? matches all files which have a 2 letter file extension matches all files which have a 2 letter file extension
[xyz+]* matches all files starting with x,y or z or +
[a-f]* matches all files starting with a,b,c,d,e or f (range)
[a-fxyz]* matches all files starting with a,b,c,d,e, f (range) or x,y,z(list)
[^xyz]* matches all files not starting with x,y or z
[^a-f]* matches all files not starting with a,b,c,d,e or f (range)
[^a-fxyz]* matches all files not starting with a,b,c,d,e, f or x,y,z
ab\? matches all files not starting with 'ab' and then containing '?'
[a-c]m*.[^ch]* matches all files starting with a,b or c,

always followed by the letter m,

followed by any number of characters (or none),

always followed by the '.' character,

followed by any character except c and h (in the file extension)

followed by any number of characters (or none)

UnixDos Argument Expansion Extensions

In addition the already powerful UNIX "Regular Expression"(re) search mechanism UnixDos provides the following added features:

FULL INVERSION
!{re} Full Invert: Matches any file NOT fulfilling the regular expression '{re}'.
!*.c matches all files NOT having the file extension '.c'
!*.* matches all files which have NO file extension

SELECTIVE INVERSION
!{re1}!{re2} Selective Invert: Matches any file NOT fulfilling the regular expression '{re1}'

within all files matching '{re2}'.

![d-m]*!*.c matches all files with file extension '.c' which do NOT start with d,e,f,g,h,i,j,k,l,m
!x*!*.zip matches all "*.zip" files which do NOT start with the letter "x"

ARGUMENTS  PULLED IN FROM FILE
@lst File List: Reads text file 'lst' and places each line as a separate argument
@new.lst Read all lines in file "new.lst" and convert each line into a separate argument

Example:

text file 'new.lst' contains the following 5 lines:

*.c
*.cpp
*.h
*.hpp
*.ipp

The following command line:

ls @new.lst

is translated into::
ls *.c *.cpp *.h *.hpp *.ipp

which again is translated into: all C/C++ Sources and include files and inline files

(instead of 'ls' any other UnixDos utility could be used - see "show_exp" for more info)

EXPANDING ENVIRONMENT VARIABLES (also in UNIX)
$env Env.Variable: UNIX style access to an environment variable '$env'.
set CLST=*.c

ls $CLST

translated to: ls *.c becomes: ls {all C Sources}
(instead of 'ls' any UnixDos utility could be used!)
%env Env.Variable: DOS style access to an environment variable '%env''.
%env% Env.Variable: DOS style access to an environment variable '%env%''.
set CLST=*.c

ls %CLST

translated to: ls *.c becomes: ls {all C Sources}
(instead of 'ls' any UnixDos utility could be used!)

.

  AUTOMATIC ENVIRONMENT VARIABLE FOR EACH UnixDos UTILITY
$UD{prog} Automatic Environment Variable:
$UDLS Automatic environment for LS utility

UnixDos will automatically include the contents of these automatic program Environment Variables for the current program/utility
(if it is set with the set UDXX=value)
The name is composed of "UD" in the beginning directly followed by the capitalized letters of the program.

Example:

program "df" would use env Variable "UDDF".

This means you can easily customize the desired default behavior of any UnixDos utility, by setting the corresponding environment variable! - for example to NOT get an error message for files from RM which are already gone use the silent option in the default UDRM environment variable:

set UDRM=-s

Example:

set UDLS=-lt

ls *.c     becomes:
ls -lt *.c

To alert you about the automatic inclusion of the default arguments it will display the following message:

Adding default environment: $UDLS=-lt

To suppress this informational message insert the '!' character in from of the value:

set UDLS=!-lt

This will suppress the message but still use the value after '!'

If you want to specify several arguments use the UnixDos separator:

set UDLS=-lt;*.c;*.h;*.cpp;*.hpp

To change the separator specify your separator character in the UnixDos configuration file (ud.cfg)
(instead of 'ls' any UnixDos utility contains this feature,

  SUPPRESS EXPANSION (also in UNIX)
'arg' No Expansion: If arguments are enclosed in forward single quotes any expansion is suppressed.
Will NOT expand '*.c' into the list of C source but passes this "regular expression" on to the 
"ufind" UnixDos utility which does the expansion internally

.

  WRITE STRING AUTOMATICALLY TO A FILE
~text File text exchange:
This feature allows you to pass text "text" into any UnixDos utility via a file reference.
UnixDos will write the "text" to a temporary file(fileex01.tmp, fileex02.tmp...) and then replace the "~text" argument with that temporary filename.
~[fn~]text uses "fn" instead of the default temporary file names (fileex01.tmp...)

Example:

cut -f2 "-d;" ~$PATH

Will display the second directory found in the $PATH environment.

cut -c1-10 "~text1.tmp~This is straight text"

Will show the first 10 character of the text and create file 'text1.tmp':

This is st

EXECUTE PROGRAM(S) AND USE THE OUTPUT AS ARGUMENTS (also in UNIX)
`cmd` Run Program(s) "cmd"
Will execute all command(s) within backward single quotes 'cmd' and places each line in the output as a new argument on the command line.
   

Example:

banner `udate`

Will show run 'udate' (which gives the "Day-of-the-Week Month Day") and then place the output as one argument for the 'banner' program to show the date in big letters:

#     #                            #                             #####     #
#  #  #  ######  #####            # #    #    #   ####          #     #   ##
#  #  #  #       #    #          #   #   #    #  #    #               #  # #
#  #  #  #####   #    #         #     #  #    #  #               #####     #
#  #  #  #       #    #         #######  #    #  #  ###         #          #
#  #  #  #       #    #         #     #  #    #  #    #         #          #
 ## ##   ######  #####          #     #   ####    ####          #######  #####

This is a very powerful feature which allows you to run one or several commands and convert each line in the output to a new argument.
You can even use redirection and piping within your command sequence!

 

UnixDos CONFIGURATION FILE (unixdos.cfg)

Since the default characters for:

will be immediately executed from the "Shell" we replaced them with the following defaults:

PIPE=# DOS/UNIX defaults to "|" banner `ls # wc -lt`
IN={ DOS/UNIX defaults to "<" banner `wc { x`
OUT=} DOS/UNIX defaults to ">" banner `wc *.c } x`
SEP=; Separates the commands banner `ls } x; wc { x`
FEX=~ File exchange symbol, write automatically a string to a file cut -c2-10 ~mytext

You can redefine any of these values by placing "Config Commands" in the 'unixdos.cfg' UnixDos configuration file in the same directory
where the all the UnixDos utilities are located.

Example:

banner `udate } wrk.tmp;cut -f3,2,5 { wrk.tmp`

 #####     #               #                               #     #####   #####
#     #   ##              # #    #    #   ####            ##    #     # #     #
      #  # #             #   #   #    #  #    #          # #    #     # #     #
 #####     #            #     #  #    #  #                 #     ######  ######
#          #            #######  #    #  #  ###            #          #       #
#          #            #     #  #    #  #    #            #    #     # #     #
#######  #####          #     #   ####    ####           #####   #####   #####

Will first run 'udate' and then place the output into file 'wrk.tmp'.
Then it will redirect file 'wrk.tmp' as input into 'cut' and select fields 3,2 and 5 in that order.

To eliminate the extra blanks use:

banner `udate}x1;cut -f3,2,5{x1}x2;sed \"s: ::g \" x2`

 #####     #       #                       #     #####   #####   #####
#     #   ##      # #    #    #   ####    ##    #     # #     # #     #
      #  # #     #   #   #    #  #    #  # #    #     # #     # #
 #####     #    #     #  #    #  #         #     ######  ###### ######
#          #    #######  #    #  #  ###    #          #       # #     #
#          #    #     #  #    #  #    #    #    #     # #     # #     #
#######  #####  #     #   ####    ####   #####   #####   #####   #####



Regular Expression for Text Searches

Some UnixDos utilities use "regular expression" to select specific text pattern from text files.

The following UnixDos utilities use text searches: grep, egrep, fgrep, sed, ufind, umore, which.

The following additional meta characters are available:

^ Line Begin: Refers to the beginning of each line.

Example:

^a* matches all lines starting with letter 'a'.

^[^m-w]* matches all lines NOT starting with m,n,o,p,q,r,s,t,u,v,w

$ Line End: Refers to the end of each line.

Example:

a$ matches all lines having the letter 'a' in the last column

[^a-f]$ matches all lines NOT having the 'a' thru 'f' in the last column

. Wildspace: Matches any single character. (? is only used for File matching!)

Example:

^..[a-f] matches all lines starting with exactly 2 characters always

followed by a,b,c,d,e or f

[D0-9].$ matches all lines ending with D or a single digit and always

followed by any single character

Regular Expression for Text Search/Replacement

Some UnixDos utilities use "regular expression" to select specific text pattern from text files and define a replacement for those patterns:

sed

The following additional meta characters are available to use "groups" as separate pieces of the substitution pattern:

\( Group Start: Indicates the beginning of a substitution group.

\) Group End: Indicates the ending of a substitution group.

Example:

\(a$ matches all lines having the letter 'a' in the last column

[^a-f]$ matches all lines NOT having the 'a' thru 'f' in the last column

\n Group Ref: Refers to group number 'n'.

Example:

\3 refers to group number 3

Example:

In this we first get the list of all environment variables:

set > set.lst

HELPFILES=c:\windev\help
HOMEDRIVE=C:
HOMEPATH=\users\default
INCLUDE=c:\madhur\src\dx\def;\msvc\include
INIT=C:\MSVC
ISLVINI=t:\pvcs
LDFLAGS=/B/NOI/NOE/SE:1000/ST:4000
LDLIB=llib
LIB=c:\madhur\lib;c:\msvc\lib
LIBPATH=t:\pvcs\dos

In this example we switch column 2 with column 1 using '=' as delimiter and insert the text 'is the value of':

sed "s:\(.*\)=\(.*\):\2 is the value of \1:" set.lst

the output is:

C: is the value of HOMEDRIVE
\users\default is the value of HOMEPATH
c:\madhur\src\dx\def;\msvc\include is the value of INCLUDE
C:\MSVC is the value of INIT
t:\pvcs is the value of ISLVINI
/B/NOI/NOE/SE:1000/ST:4000 is the value of LDFLAGS
llib is the value of LDLIB
c:\madhur\lib;c:\msvc\lib is the value of LIB
t:\pvcs\dos is the value of LIBPATH

How to get Help

Each UnixDos utility has an inbuilt short help screen explaining all the options and switches available for that utility.
If the UnixDos utility has no required arguments you will automatically get a short help display when you type the utility name.

Example:

cp requires at least two arguments (the "source" and "destination"):

cp

Will display (after the initial 2 intro lines):

cp (Copy files)
usage: cp [-{l|f|v}] {src} {dest}
-f = force : always remove old files (even if read-only)
-l = list : show which file is currently copied
-v = verify: verify that input is identical to output
src = source file(s)
dest = destination (has to be directory if several source files)

Those UnixDos utilities which do NOT require any arguments will display the help screen when you enter the argument '-?'.

Example:

LS requires no arguments (in which case it display all files in the current directory);

to get help type:

ls -?

Will display (after the initial 2 intro lines):

ls (List files and directories)
usage: ls [-CFRdelrstxy] [files]
-C = COLUMN : suppress multi column output
-F = : suppress '/' for directories, '*' for execs
-R = RECURSIVE: list all subdirectories
-d = DIRECTORY: show only directory detail NOT all files in it
-e = EXTEND : show filesize in extended format (30,764,678)
-l = LONG : long listing (default sort by name)
-r = REVERSE : reverse the sort order
-s = SIZE : sort by file size (show 1k increments)
-t = TIME : sort by time
-x = ACROSS : sort across lines instead of down the column
-y = TYPE : sort by file type/extension
(If the output is redirected to a file LS automatically prints each file
on a separate line: ls > lst.tmp)

Differences between DOS and UNIX:

Filename Separator:

UNIX separates the filename and directory with the forward slash '/' (e.g "/usr/src/file.c").

Unfortunately DOS changes this and is using the backward slash '\' (e.g "\USR\SRC\FILE.C").

UnixDos allows you to enter files in both forms and will always convert to the UNIX notation unless you enclose in single quotes (e.g. '\usr\src\file.c')

Filenames:

DOS has the following fixed structure for the filenames:

up to 8 places for the filename + up to 3 for the extension (e.g. FILE.TXT).

UNIX allows a longer filename (14 or in "Berkeley UNIX" up to 255 places) and uses the separating dot just as any other character - so you can have several "extensions" of various lengths ('file.longext' or 'programname' or 'lex.a.c' are valid filenames)

User groups:

UNIX provides three user groups and connected layers of restrictions:

the owner, the group and others DOS has only one: the owner

File links:

UNIX allows access to the same file using different name(s) - so called "links" (not "hot dogs").

DOS does not provide this feature.

File access times:

UNIX maintains 3 different file times:

creation time, modification time and last access time

DOS/Windows 3.X maintains only the modification time,
but Windows 95/NT do maintain those three times.

Pipes: prog1 | prog2

UNIX allows you to run several programs simultaneously and connect the input of one program to the output of another program

via a "pipe". This communication is done entirely in memory and is therefore very fast and does not require any additional disk space.

DOS does not allow you to run two programs simultaneously so DOS will run the first program until it completes, store the output in a temporary disk

file and then start the second program and feed it the temporary disk file (output from prog1) and remove it after it has been read

(unless you interrupt with Ctrl-C) in which case you get lots of "left-overs" sitting around.

Argument expansion:

UNIX will expand the arguments before any program starts using the "Shell" (Bourne Shell, C Shell or Korn Shell). This means that the program does not have to worry about translating any expressions into the proper argument list (i.e. translate '*.c' into the list of all C source files).

DOS(COMMAND.COM) will not expand any arguments for you. So each UnixDos utility has to do this argument expansion job individually.