Dec 162017
Unix-like command shell.
File CSH.ZIP from The Programmer’s Corner in
Category C Source Code
Unix-like command shell.
File Name File Size Zip Size Zip Type
BACKUP.C 476 250 deflated
CAT.C 1232 571 deflated
CD.C 231 165 deflated
CHMOD.C 2315 681 deflated
CMDS.C 2773 1091 deflated
CP.C 3523 1163 deflated
CRLF.C 59 58 deflated
DOPROG.C 180 131 deflated
DRIVE.C 214 162 deflated
ECHO.C 193 139 deflated
ENV.C 2922 1085 deflated
FEXEC.ASM 1134 538 deflated
FEXECV.C 1119 571 deflated
FEXECVP.C 1017 403 deflated
FGREP.C 2093 854 deflated
GETCMD.C 1453 575 deflated
INVALID.C 248 164 deflated
LS.C 6275 1952 deflated
MAIN.C 11582 3282 deflated
MAKEFILE 989 436 deflated
MD.C 121 94 deflated
MORE.C 3888 1429 deflated
MV.C 2137 721 deflated
PUSHD.C 1039 404 deflated
PWD.C 268 182 deflated
RM.C 537 300 deflated
RMDIR.C 240 167 deflated
SAVESTR.C 243 175 deflated
SHELL.COM 26352 15286 deflated
SHELL.DOC 12504 4827 deflated
SHELL.LNK 255 145 deflated
STDSAVE.C 438 237 deflated
TOUCH.C 104 93 deflated
Y.C 2039 637 deflated
_CROOT.C 5369 1991 deflated

Download File CSH.ZIP Here

Contents of the SHELL.DOC file

shell.exe command processor for ms.dos

This is yet another replacement. It implements unix-like
shell commands (ls, mv, fgrep, rm, chdir, chmod) etc. Other features

1. Command line expansion of ambiguous file names.

Programs invoked from shell never see '*.*' as an argument - they see
the list of all matching files in the current directory.

2. History substitution - ala C-shell.

History substitution is a powerful means to save retyping of long
command lines.It allows you to do things like re-execute the last command,
re-execute the last command but redirect output to a file, or execute a
new command with arguments from previous command lines. The last 20
commands are saved, and can be reviewed by typing the 'history' command.

Previous commands can be referred to by their number, or relative to
the current command's number. Parameters from previous commands can be
seperated out and used individually.

History substitutions specifications come in two parts - the command
number specifier and the argument specifier, seperated by a colon. The
argument specifier is optional; if it is omitted, the entire command line
is specified.

::= !! | !n | !-n
!! = last command
!n = nth command
!-n = command n commands before current command number

::= :[^$*] | :n | :n* |
n = number of argument (0 being the command name)
^ = first argument (i.e. argv[1])
$ = last argument
* = ^-$, or nothing if only one word on command line
n* = arguments n through $


This is not as complicatated as it may appear. Here is an example session.

0% ls *.c
foo.c bar.c
1% more foo.c
/* edit the last argument of the last command */
2% edit !!:$
/* go off and edit */
/* reference last argument of last command */
3% fgrep foo !!:$ bar.c
FOO.C : foo

BAR.C : foo
/* edit the second thru the last args of command 3 */
4% edit !3:2*
(go off and edit)
/* repeat last command */
%5 !!
(go off and edit)
/* remove the 1st argument of the command 2 before the current one */
%6 rm !-6:^

History substitution here is a compatible subset of the C-shells
history substitution facility. Cshell allows even weirder combinations.

3. Multiple commands on one command line - Command lines are split at
semicolons. example:

%0 ls -l *.c ; make shell.exe ; exit

4. Character escapes and argument quoting - i.e. '\;' suppresses the
command parser from seeing the semicolon as a command seperator.

Quotes are handled thusly:

1. String surrounded by single quotes are stripped of the single
quotes, and passed without wild-card expansion to the invoked program.

2. Strings surrounded by double quotes are passed complete with quotes
to the calling program. This was done for a version of grep that I have
that accepts regular expressions with embedded blanks within double quotes.

5. Many builtin commands.

a: b: c: cat
cd chdir chmod cls
commands copy cp copy
d: del dir e:
echo era erase error
exit f: fgrep g:
h: hist history i:
j: ls md mkdir
more mv no history popd
pushd pwd rd rm
rmdir set tee touch

There are many that are simply aliases, e.g. 'copy' and 'cp' invoke the
same program.

6. commands description syntax

terms used in syntax explanations :

fname ::= PC-DOS ambiguous or unambiguous file or directory name.

uname ::= unambiguous PC-DOS file or directory name

string ::= any string of printable chars of arbitrary(<512) length.

filelist ::= filename [filename .. filename]

noargs ::= no arguments at all

{arg} ::= term is optional

envstring ::= =

7. command syntax

drive a: | b: | c: | d: | e: | f: | g: | h: | i: | j:

changes default drive. If you don't have such a drive, nothing happens.

cat cat {}

copies specified files to standard output. If none are given, copies
standard input to standard output

cp cp | copy

copies specified files to destination file or device. If more than one
file is in the file list, must be a directory.

cd cd | chdir

makes the current default directory.

chmod chmod {-|+[rwh]*}

change file permissions for specified files

+r, -r turn on or off read permission - i.e. hide the file.
+w, -w turn on or off write permission.
+h, -h turn on or off hidden attribute - converse of r
+a, -a turn on or off archive attribute

Note that '-r' or '+rwh' are both valid syntax for switches. Also new
permission switches are permissable between file names with the following
warning: I don't reset the masks between file names - if you have a second
batch of attribute changes on the command line, the effect is additive.
If you're not careful, you could make a mess of a files attributes.

If you don't specify any attribute switches, file attributes will be
set to 0, which means read,write,not hidden, not system, not modified since
last backup.

cls cls | clear

clears the screen and homes the cursor.

commands commands

prints a table of available built-in commands.

del del synonym for rm.

dir dir synonym for ls.

echo echo echos argument list to screen.

era era synonym for rm.

error error

prints returned value of last command to the screen.

exit exit terminates execution of the shell.

fgrep fgrep

looks for unambiguous pattern in . echos lines
matching to the screen.

hist hist | history prints history list to standard output.

ls ls | dir {-[alqcr]} Lists files that match

-a all files, including system files are listed. '.' and '..' are
suppressed, but you know they're there if you need them, don't you?
-l prints out file times, permissions, etc
-q suppresses header line from display - useful when you want to pipe
stuff into another program.
-c print as one column.
-r recurse through all encountered subdirectories.

md md | mkdir

make a directory. Prints an error if it can't be done

more more {-[0-9]*} {} List file to screen with pauses

-n specify tab width when expanding tabs, where n is an integer.
more acts like 'cat' when redirected - you can concatenate files in this
manner. If no files are specifed, standard input is 'mored.'

mv mv

moves specified file or files to target specifed by . If there
is more than one file in list, must be a directory

popd popd returns to directory at top of directory stack.

pushd pushd

save current working directory on directory stack, and changes current
working directory to .

pwd pwd prints current working directory to standard output.

rd rd | rmdir remove specified directory if possible.

rm rm {-q}

blows away all files in . If -q is specified, will ask if
they should be removed.

set set { { .. }}

sets a string in the environment. If you specify 'name=' with no
string after, it will remove it from the environment. If you don't specify
a string, set prints out current environment.

tee tee

Copies standard input to standard output, depositing a copy in

touch touch

Makes modification time of specified files the current date and time.

y y

copies standard input to standard output, then copies the specified
files to standard output. Sort of the opposite of tee, in other words.

7. Helpful hints

Use forward slashes in all path names - they get converted to back
slashes before dos hears about them. If you are invoking a program that
expects forward slashes (DOS external commands for instance) precede it
with a back slash.

Put single quotes around arguments with semicolons in them, so they
don't turn into command delimiters.

The set command affects only the local shell's environment. You can
'exit' to and the original environment is intact. The local
environment is 4K large - which is useful.

Exit and re-invoke if you have trouble loading large programs from it
- shell dynamically allocates and frees memory all the time, but the AZTEC
run-time doesn't tell DOS to shrink memory.

8. Implementation notes

DOS doesn't acknowledge a 'change default drive' command until you
issue a 'get current directory' call. Why? The only way I figured this out
was by disassembling

This was developed with AZTEC C by MANX. In it are a few hacked up
pieces of AZTECS library source, which I hereby acknowledge. If MANX has a
problem with me distributing them, they can call me direct - I figure I'm
doing them a favor by disseminating this program as an example of the power
and quality of their compiler and development tools.

If you have the AZTEC compiler and MANX's version of make, you can
recreate the shell from source, by using arc to unpack everything into a
directory, editing the macros BINDIR and CLIB and then making I
wouldn't try it with any other compiler, because I make a lot of calls to
AZTEC specific routines. You can write your own commands and add them by
editing cmds.c, and putting the name of your subroutine and its associated
command string into the builtin array.

You can safely modify any of my builtins, as long as you don't assume
that all of your static variables are going to stay initialized to startup

Any of the other code (main.c, fexecvp.c fexecv.c) modify at your own
peril. I break them every time I do it, and I wrote them!!!

PC|MS-DOS has a limit of 20 file handles. If you add a command that
opens files, make sure you catch the ctrl-break signal and close them.
Look at CAT.C or Y.C for examples.

External DOS commands have trouble parsing the command line when
invoked from shell. The command line gets garbled. I spent a lot of time
trying to figure this problem out to no avail. They apparently get their
command line arguments some way that is a mystery to me. The only solution
is either to either run, or 'exit' to the original command

This problem has kept me from running this as a straight
replacement. It just goes to show that Microsoft and IBM have one hell of a
time following their own rules.

Programs compld by AZTEC C that don't set up their own signal handlers
seem to be 'unbreakable' - you can't ctrl-break out of them, as though
SIGINT is set to SIG_IGN before entry. You might not want to invoke such a
program if it lasts hours and you want to be able to break out of it.

550 2nd ST. S.E.
Cedar Rapids Iowa 52401
(319) 338-6053 (HOME VOICE)

 December 16, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>