I would like to get more details on what the below command is doing:

PASSING=0 FAILED=0 > log_${ENV} print "Test Started at `date`\n"

closed as off-topic by dr01, user88036, jimmij, schily, Jeff Schaller Oct 18 '18 at 10:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." – dr01, jimmij, schily
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    What shell is this written for, ksh93? – Kusalananda Oct 10 '18 at 12:05
  • A related questionis unix.stackexchange.com/questions/474477 . – JdeBP Oct 10 '18 at 13:05
  • This question is neither off-topic [Shell scripting is valid][unix.stackexchange.com/help/on-topic] nor too-broad. It is about an specific command, as shown. – Isaac Oct 11 '18 at 6:28
  • We would like more context on where this command is from. For all we know, print may be a function, and that function uses PASSING or FAILED. – muru Oct 11 '18 at 7:30

The command may be rewritten as

PASSING=0 FAILED=0 print "Test Started at `date`\n" >log_${ENV}

as the redirection may occur at any point on the command line.

The redirection sends the output of the print command to the file named log_${ENV} (or log_$ENV, the curly braces won't do anything here), where ENV is supposedly a shell variable with some value that exists in the current environment.

The two assignments to PASSING and FAILED will set these two variables in the environment of the print command. They will not exist after the execution of this line (unless they existed before in the script, in which case their original values would remain unmodified after execution of this command line).

Since print does not seem like it's using these two variables (unless it's a script or a function or something else that we don't know about), it's difficult to say what the intention is with the variables.

The print thing takes a text string as its only argument, where a part of the string is an old-styled command substitution that will expand to the output of the date command before print is invoked. Using a more modern command substitution syntax, the argument could also be written as "Test Started at $(date)\n".

The overall effect would probably (depending on what print does) be to write the given text string into a specific file whose name depends on the value $ENV.


In ksh93 (and zsh), print is a shell built-in utility that acts (loosely speaking) a bit like echo. That shell also treats $ENV in a special way in that it will source the file that $ENV points to when starting an interactive shell. Using it (or upper-case variables in general) as a generic variable in a shell script is not advised.

Related to this:


You have to "parse" (interpret) the command line (divide into words):

PASSING=0 FAILED=0 >log_${ENV} print "Test Started at `date`\n"
\___  __/ \__  __/ \___  ____/ \_ _/  \_________  ____________/
    \/       \/        \/        \/             \/
   var1     var2    redirect    cmd    "Argument to command".

Those are the five words (divided on spaces) that make up the command line.

  • A var before a command, like in var=123 cmd will be defined in the environment for (only) the duration of the command execution. Then, it will be discarded.

    Several variables could be defined before the command name.

  • A redirection is used to send output to a file or read input from a file. A redirection could appear at any place of the command line and will be applied for the whole command line (command execution).

    In this case, the redirection is to output to a file called as the concatenation of the word log_ and the value inside the variable ENV (the $(ENV) part).

  • Obviously, the command name print in this case.

    This command name exists (as builtin) in ksh, mksh,lksh and zsh, but not in ash, dash, csh, yash, bash (and others). In those shells, the command may exist as an external program to be found in the PATH.

  • Argument(s) is the list of parameters, text, or other information that is given to the command and available in c programs as argv[] and int argc or in shell as $@ and $#.

    In this case, the argument include one command expansion `date`, equivalent to (in modern syntax and strongly recommended) $(date). That part will execute the command (in this case) date and will replace the whole part with the output of the command. In short: will place the actual date at that place.

The whole command could also be written (to the exact same effect) as:

PASSING=0 FAILED=0   print "Test Started at `date`\n"     >log_${ENV}

Which, not having enough information, seems to be printing one string into a log file. If it is indeed the built-in print mentioned above, the two variables will have no effect and could be erased to write the command as :

print "Test Started at `date`\n"     >log_${ENV}

But that is just an educated guess, to actually know what is the print command doing, you need to dig a little deeper. You need to say which shell is running the command and (if valid for your shell), the output of type print.

Not the answer you're looking for? Browse other questions tagged or ask your own question.