Tags: errors, korn, linux, programming, remember, reporting, run, running, script, shell, switch, syntacticallyevaluate, unix

How to "test" shell script without running it?

On Programmer » Unix & Linux

3,381 words with 4 Comments; publish: Tue, 29 Apr 2008 13:54:00 GMT; (20046.02, « »)

I seem to remember with the korn shell a switch that would syntactically

evaluate the script reporting any errors but NOT run the script.

Is something like this available with bash?

If so, please advise? I've looked through the bash docs and man pages but

cannot seem to find anything.

TIA

All Comments

Leave a comment...

  • 4 Comments
    • Use the -n option:

      bash -n script

      In vim I have a ksh script called compile tied to F4.

      It determines the type of script and calls the appropriate

      routine (ksh -n for ksh, perl -c for perl).

      It has saved me endless agony over the years.

      Dan Mercer

      "bobmct" <bobm3.unix-linux.todaysummary.com.worthless.info> wrote in message news:4Lduh.1$ji5.4167.unix-linux.todaysummary.com.news.

      ntplx.net...

      : I seem to remember with the korn shell a switch that would syntactically

      : evaluate the script reporting any errors but NOT run the script.

      :

      : Is something like this available with bash?

      :

      : If so, please advise? I've looked through the bash docs and man pages but

      : cannot seem to find anything.

      :

      : TIA

      #1; Tue, 29 Apr 2008 13:55:00 GMT
    • Dan Mercer wrote:

      > Use the -n option:

      > bash -n script

      > In vim I have a ksh script called compile tied to F4.

      > It determines the type of script and calls the appropriate

      > routine (ksh -n for ksh, perl -c for perl).

      > It has saved me endless agony over the years.

      > Dan Mercer

      >

      Thanks, Dan;

      That's what I was looking for! Funny, thought, I still don't see reference

      to it int he bash docs...

      But, it does what I was looking for.

      Thanks again.

      bobmct

      #2; Tue, 29 Apr 2008 13:56:00 GMT
    • Hi bob,

      For the K shell what is option we need to choice just for the systax

      checking , is ksh -n script ?,is this way u r testing ...

      Regards

      Gori Akthar

      On Jan 26, 6:05 pm, bobmct <bobm....unix-linux.todaysummary.com.gmail.com> wrote:

      > Dan Mercer wrote:

      >

      >

      >

      >

      > That's what I was looking for! Funny, thought, I still don't see referenc

      e

      > to it int he bash docs...

      > But, it does what I was looking for.

      > Thanks again.

      > bobmct

      #3; Tue, 29 Apr 2008 13:57:00 GMT
    • On Jan 29, 8:04 pm, "oracle DBA" <mansur....unix-linux.todaysummary.com.gmail.com> wrote:

      > Hi bob,

      > For the K shell what is option we need to choice just for the systax

      > checking , is ksh -n script ?,is this way u r testing ...

      > Regards

      > Gori Akthar

      > On Jan 26, 6:05 pm, bobmct <bobm....unix-linux.todaysummary.com.gmail.com> wrote:

      >

      >

      >

      >

      >

      >

      >

      >

      >

      Very Good for "test" shell script. Below is my output.

      moonhk.unix-linux.todaysummary.com.hex:/mnt/disk2/ux3/shell$ ksh -n xall.ksh

      xall.ksh: warning: line 18: `...` obsolete, use $(...)

      xall.ksh: warning: line 19: `...` obsolete, use $(...)

      xall.ksh: warning: line 20: `...` obsolete, use $(...)

      xall.ksh: warning: line 26: `...` obsolete, use $(...)

      xall.ksh: warning: line 30: `...` obsolete, use $(...)

      xall.ksh: warning: line 32: `...` obsolete, use $(...)

      xall.ksh: warning: line 35: `...` obsolete, use $(...)

      xall.ksh: warning: line 40: `...` obsolete, use $(...)

      xall.ksh: warning: line 40: `...` obsolete, use $(...)

      xall.ksh: warning: line 67: `...` obsolete, use $(...)

      moonhk.unix-linux.todaysummary.com.hex:/mnt/disk2/ux3/shell$

      xclient=`ps -ef | grep progres | grep /data | wc -l`

      #4; Tue, 29 Apr 2008 13:58:00 GMT