As we are aware that, from the following command, output of less --help | grep -i examine is redirected to the file examine-files-in-less, Is there any generic order of operation used by linux similar to BODMAS rule that we have in mathematics?

less --help | grep -i examine > examine-files-in-less

All commands involved in a pipeline such as the one in the question are started (pretty much) at the same time.

This means that the commands in a pipeline such as

find . ...some other arguments... | sort | uniq -c | sort -nr

are all running in parallel.

However, since the output of one command is the input to the next, and since commands wait for input to be delivered and for output to be consumed, the data synchronizes the commands in the pipeline.

In the above pipeline, for example, the last sort will be running, but won't do much until all the output of find has been consumed by the first sort (a sorting operation requires that all available data has been read).

The data, hence, enforces a left-to-right ordering in the processing done by the pipeline.

In other compound commands, such as the list

ls -l; cat somefile

which is the same as

ls -l
cat somefile

there is a strict left-to-right ordering. cat will not start until ls has finished.

In a compound command such as

test -f filename || echo 'no such file'

there is also a strict left-to-right ordering, and here, echo will not execute if test returns a zero exit status.

See also, for example, "Issue with booleans tests && and || in bash" and "Precedence of logical operators versus semicolon".

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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