[svlug] Newbie ques: How to echo commands from a script file

William R Ward bill at wards.net
Tue Jan 8 11:22:02 PST 2002

"Todd G. Gardner" <nicoli at bigfoot.com> writes:
> I am running rh72.
> How do I cause all the commands from a script file to echo to the 
> terminal window.
> echo on does not seem to work if I put that in my script file

Depends on what scripting language you are using.  "echo on" is for
MS-DOS batch files, which is a different scripting language.

On Linux you're probably using a shell or Perl script.  If it's a Perl
script, you can't do it; you'll have to insert "print" statements into
your program.  But from your description I'm going to assume it's a
shell script.

You'll need to find out which type of shell script it is: Bourne (or
one of its derivatives) or C (or tcsh) shell.  If you don't know, see
the "P.S." comment below for some tips for finding out.  Once you know
what type of shell you are using, then here's the answer...

For Bourne shell (or ksh, zsh, bash, etc.) you want the -x option.  On
the command line you can type "sh -x <script>" to run it with echoing
turned on.  Or, you can use the commands "set -x" and "unset -x"
within the script to turn echo on and off.

For csh or tcsh, the "-x" option will work, as in "csh -x <script>",
or you can use the commands "set echo" and "unset echo" inside the


P.S.: How to tell what kind of shell you are using...

Shell scripts come in two major types: Bourne and C shell.  The
original Unix shell was the Bourne shell, /bin/sh, which is the basis
for most Unix scripting.  Shells such as the Korn shell (ksh), Z shell
(zsh), and Bourne Again shell (bash) are all derived from the Bourne

The other family is the C shell (csh) which also includes the TENEX C
Shell (tcsh).  Although many people like to use csh or especially tcsh
for their login shell, it is generally thought to be a poor choice for
scripting for a number of reasons I don't want to go into here.

How to tell what type of script it is depends on how you run it:
 * If you run it by typing the name of the shell followed by the
   script name, then you already know what kind it is.
 * If you run it by typing "source <script>" then you
   are using csh or tcsh.
 * If you run it by typing ". <script>" then it is one of the Bourne
   shell family.
 * If you run it as you would run any other program, by just typing
   the name of the script, then look at the first line of the file: it
   should start with "#!" followed by the name of the shell.

William R Ward            bill at wards.net          http://www.wards.net/~bill/
     If you're not part of the solution, you're part of the precipitate.

More information about the svlug mailing list