Main Help Page | Home Page (Internet) | Menus and Windows | Release Notes

Scripting

Zoom Shell has a scripting language. You can place a bunch of commands in a file, and execute them. Unless you specify otherwise, they will run serially -- the next command after the first is complete*. Zoom Shell has three commands to allow for looping and branching; if, for, and while. Please peruse all the samples in the samples directory to see working scripts. For more examples and more complete documentation of the scripting features, check (and re-check) the samples on the web. If you write a script that you would like to share with others, please send me and e-mail or paste the text in my entry form.

Test

The heart of the if statement is the test command. You can test for a bunch of things, such as the presence of a file, equality of a numeric expression, or comparison of a string.  Please view "test_fun.zsh" in the samples directory to see a complete set of examples.

test -f readme.txt (test to see if "readme.txt" is a normal file)

In an if statement, the word test is usually substituted for square brackets. In this release of Zoom Shell, the following four lines are equivalent:

if [ -e zsh.exe ] then
if test -e zsh.exe then
if test [ -e zsh.exe ] then
if -e zsh.exe then

Each line allows if to test to see if "zsh.exe" is a file. The first of the four lines is the preferred one, and the last two may not continue to be supported in future versions of Zoom Shell.

One big limitation is that test does not allow for an "and" or "or" in the test expression. You can do "not" as follows:

if [ ! -e zsh.exe ] then

If

The if statement allows for conditional processing. The basic flow is as follows:

if [${j} -eq 4] then
  echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
elif [ ${j} -eq 3 ] then
  echo $0 $1 $2 $3 $4
elif [ ${j} -eq 2 ] then
  echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else
  echo 
fi

In this version, you can subsitute "endif" for "fi". You can also substitute "elsif" or "elseif" for "elif."

For

The for statement allows for looping through a list or a sequence of numbers. The basic form, in which for reads each line from a file,  is as follows:

for FileName 
in <filelist.txt
do
  echo ${FileName}
done

You can also run a command to generate a list:

for FileName 
in `grep -l Zoom *.html`
do
  echo ${FileName}
done

Or give a file specification:

for FileName 
in *.html
do
  echo ${FileName}
done

The final form of the for command allows one to go from one number to another:

for j 
in 1..4
  do
    echo ${j}
done

The form of the for command shown above only allows you to increment by one.

While

The while command has two forms; one that reads through a file, and another that tests a variable.

Read through ${TempFile}:

while read FileLine 
  do
  if  [${FileLine#%Basedir%\} = ${SearchExpr}]  then
     echo ${FileLine#%Basedir%\}
  fi
done < ${TempFile}

Test the value of a variable:

j=0
while [ ${j} -lt 10 ]
do
  j=evaluate(${j}+1)
  echo ${j}
done

Continue

Inside a loop, continue causes Zoom Shell to go back to the previous for or while.

Exit

Inside a loop, exit causes Zoom Shell to exit out of the loop. Outside of a loop, exit causes Zoom Shell to terminate the script.

Shift

Shift will shift all the numbered arguments in a script back one -- the script name and its arguments are numbered from 0 to n. Shift will place the first argument in the variable ${0}, the second in ${1}, etc. Subsequent shifts will move the variables again -- the second will be in ${0}, and the third in ${1}.

Verbose, Noverbose

verbose instructs Zoom Shell to print each line of the script before executing. At the begining of each line thus printed, Zoom Shell prints whether the line was in an "if," "for," "while," or "main" loop. The "if" status information includes a number indicating the level of nesting.

* Note: On NT systems, Zoom Shell might not wait for 16 bit applications. It also will not wait for applications that are loaded by a process that spawns another.

Table of Contents