Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is print a function or statement.

Why parentheses are not required?

I couldn't find any information about this topic.

share|improve this question
up vote 1 down vote accepted

print is a statement that doesn't require (but optionally accepts) parentheses.

The entire list of items may optionally be enclosed in parentheses. The parentheses are necessary if any of the item expressions uses the `>' relational operator; otherwise it could be confused with a redirection

(see The print Statement)

Some people always use the parentheses, because e.g. they prefer the function syntax and it has no negative side effects.

share|improve this answer
What makes a phrase a statement is either (1) its ability to occur in certain syntactic contexts, for instance as a complete line of the awk script, or (2) its not returning a value. By either understanding, print is a statement. Both understandings are problematic though. The first because on some (but not all) awk implementations, any expression can occur in a statement context, so on this understanding all expressions would be statements. The second because assignments and user-defined function calls return values but the first is indisputably and the second is disputably a statement. – dubiousjim Apr 19 '12 at 11:18
There are also functions that don't require parentheses: getline is one example, and on some implementations of awk, you can use length without parentheses as a shorthand for length($0). – dubiousjim Apr 19 '12 at 11:20
@dubiousjim: Please feel free to edit the answer as necessary on the finer points I may have left out or not understood. – peth Apr 23 '12 at 18:37
I didn't mean to criticize your answer, but just to think out loud about the (not-immediately obvious) difficulties giving a principled account of why, for example, print is counted a statement in awk, but getline is counted a function. – dubiousjim Apr 23 '12 at 21:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .