Skip to main content

Cob command - quotes and spaces

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

Cob command - quotes and spaces

Resolution:

cob is a command run under Unix, just as grep and sed are. Unix command lines are processed by the shell. The shell expands all wildcards, environment variables, and does all word and field splitting before cob sees the command line.

In addition, cob tries to follow general Unix convention on command lines where possible.

Before proceeding further, we will define a cob flag such as -C and -N as an option flag, and the string that follows an option flag as an option parameter.

As noted in the Server Express documentation an option parameter must either be a string containing no spaces, or an arbitrary string enclosed in quotes. Unless environment variable expansion is required, single quotes are preferred. These quotes are removed by the shell but the option parameter is passed to cob as a unit, so cob knows the entire string consists of checker/ncg options. Some examples may help.

   cob -C bound a.cbl b.cbl

cob will compile a.cbl and b.cbl, passing bound as a directive to the checker.

   cob -C ans85 bound a.cbl b.cbl

cob will attempt to compile bound, a.cbl and b.cbl passing ans85 as a directive to the checker. This will fail because the user presumably intended bound to be a checker directive, not a file name, but did not enclose the option parameter in quotes.

   cob -C 'ans85 bound' a.cbl b.cbl

cob will pass ans85 and bound as directives to the checker, and will compile a.cbl and b.cbl. Success.

Now lets get tricky. What if a checker directive itself requires quotes or brackets.

The first thing to note is that brackets and are quotes are always interchangable in generator directives, and are generally interchangable for checker directives. constant is a notable exception. cob provides a shorthand for brackets. In any option parameter cob will convert the syntax =word into (word). As = has no special meaning to the shell it does not needed to be escaped or quoted. i.e.

    cob -C list=a.list a.cbl

will compile a.cbl passing list(a.list) as a directive. If this syntax feels uncomfortable, simply enclose the entire directive string in single quotes as in the previous example.

   cob -C 'list(a.list)' a.cbl

   cob -C 'list"a.list"' a.cbl

If a directive requires = then one must use ==. In our next examples we see single quotes being used to escape double quotes, brackets and embedded spaces, to group multiple options, as well as the use of == to represent =.

   cob -C 'constant num-dimen(10) constant err-mess"Cannot find"' a.cbl

   cob -C 'rm makesyn (low) == (lowlight)' a.cbl

One final point. The space between an option flag such as -C or -N and the option parameter is almost always optional. The following example is valid.

   cob -uCnoqualproc -Nchecknum a.cbl

However - the following equivalent example is much more readable

   cob -uC noqualproc -N checknum a.cbl

Furthermore, this removes any possibility of confusion between -C (pass option argument to checker) and -CC (pass option argument to C compiler).

The exception is when the option argument is "" - for example

  cob -xo rts -e ""

Here you must have a space between -e and "". Otherwise, after shell processing cob will simply see -e.

Old KB# 4101