nerdexam
Oracle

1Z0-821 · Question #102

Consider the following commands: What is displayed when this sequence of commands is executed using the bash shell?

The correct answer is B. cat: cannot open file1. First line (rm file1) deletes/removes file1. Second line captures the text into file2. The first part of line 3 (cat file1) fails as the file1 does not exist. The && (AND) operator will ensure that the third line fails. The result of line 3 will be the result of first part of…

Administering Oracle Solaris 11 OS on a Single System

Question

Consider the following commands:

What is displayed when this sequence of commands is executed using the bash shell?

Options

  • AHello, world
  • Bcat: cannot open file1
  • Ccat: cannot open file1Hello, world
  • Dcat: cannot open file1 Hello, World
  • Ebash: syntax error near unexpected token '&&'

How the community answered

(23 responses)
  • A
    9% (2)
  • B
    87% (20)
  • E
    4% (1)

Explanation

First line (rm file1) deletes/removes file1. Second line captures the text into file2. The first part of line 3 (cat file1) fails as the file1 does not exist. The && (AND) operator will ensure that the third line fails. The result of line 3 will be the result of first part of line 3 (cat file1). Note: cat - concatenate files and print on the standard output Note #1: A list is a sequence of one or more pipelines separated by one of the operators ;', &', &&', or ||', and optionally terminated by one of ;', &', or a newline. Of these list operators, &&' and ||' have equal precedence, followed by ;' and &', which have equal precedence. AND and OR lists are sequences of one or more pipelines separated by the control operators &&' and ||', respectively. AND and OR lists are executed with left associativity. An AND list has the form command1 && command2 command2 is executed if, and only if, command1 returns an exit status of zero. An OR list has the form command1 || command2 command2 is executed if, and only if, command1 returns a non-zero exit status. The return status of AND and OR lists is the exit status of the last command executed in the list. Note #2 (on exit status): Zero means command executed successfully, if exit status returns non- zero value then your command failed to execute.

Topics

#bash shell#command chaining#stderr handling#exit status

Community Discussion

No community discussion yet for this question.

Full 1Z0-821 Practice