1. Approach

This docu shows some tips and tricks for shell and cmd programming

Why yet another docu as all existings?

2. cmd line

Generally calling a command in a console or terminal (emulation) creates a new process starting with the named application. Usual the terminal waits till end of this process.

xterm

~ Opens a new terminal emulation in an extra window, and waits till it ends.

Writing & after the command does not wait for ending the process:

xterm &

~ The calling terminal writes the PID of the started process and is ready to get the next command.

Generally: It is exact the same if the command is part of a shell script, which is called and executed.

2.1. set environment variables to the called process

You can set some environment variables which are valid only for the called process in the same command line:

ENV1="ABC" xterm

Then you get a new process als terminal with xterm, where ENV1 is set and valid. Try: echo $ENV1 in the xterm

2.3. specific environment variables

$? is windows: ERRORLEVEL

2.4. Set environment variable in a called script

In UNIX and also in Linux there is a strong rule, not regarded for DOS or Windows batch files:

Environment variable are valid only in the own script, and declared with

extern VAR="value"

also in called scripts, but never back from a called script.

In DOS/Windows you can set an environment variable in a

call WinBat.bat

and this variable is available also in the caller. But not in UNIX/Linux.

But there is a possibility to get the same behavior also in Linux:

`. calledShell.sh`

The characteristic is the dot before the script name. Then the called script is expanded in its lines in the calling script, and hence set of environment variable in the called script will be effective also for the caller.