1

what this statement is doing in bash?

if [ ! -p "$output" ]; then

As far as I could understand ! is a not operator, "$output" is an variable but what -p signifies here?

Is it a read operation on "$output"?

Divyanshu Rawat
  • 4,421
  • 2
  • 37
  • 53
  • 2
    `man bash` `/CONDITIONAL EXPRESSIONS` : `-p file True if file exists and is a named pipe (FIFO). ` – Nahuel Fouilleul Jul 29 '19 at 14:06
  • 1
    It helps to know what `[` is. It's not shell syntax or part of `if` -- it's a command (the same command also found under the name `test`), and `-p` is an argument to that command. – Charles Duffy Jul 29 '19 at 14:08
  • @CharlesDuffy How is it duplicate where `-p` syntax is mentioned in these questions? 1 - How to find the options in if conditions of shell [duplicate]? , 2 - List of 'if' switches anywhere? – Divyanshu Rawat Jul 29 '19 at 14:48
  • @DivyanshuRawat, it's duplicate because it's a strict subset. The other questions ask about *all* the options, and their answers tell you how to get documentation for *all* the options, `-p` included. If we had a different question and answer for every single possible `test` option (`-g`, `-h`, `-L`, `-s`, `-S`, etc), that would be over 25 extra questions, adding no value over just telling people -- once -- to run `help test` (or `help [`) and read what it spits out, which is a description of *every* possible operand. – Charles Duffy Jul 29 '19 at 14:50

1 Answers1

1
if [ ! -p "$output" ]; then

It is checking if "$output" is not a named pipe.

You can check help test for all the string/file/pipe checks.

-p FILE        True if file is a named pipe.

In bash it is better and more efficient to replace [...] with [[...]] as [ is an external command and [[...]] is internal construct.

anubhava
  • 761,203
  • 64
  • 569
  • 643