Skip to main content
added 2 characters in body
Source Link
pepper
  • 2.2k
  • 5
  • 27
  • 32

Okay, the simple answer to your question is to redirect stderr to stdout. as what Fredik Phil mentioned in the comments.

instead of:

ping_results=$(ping -c 4 -q google.com);

use:

 ping_results=$(ping -c 4 -q google.com 2>&1);

or something similar...

However, depending on what you're doing, it might be better to test if the exit code of the ping command wasis 1 (indicating that the ping endedis ending in an error), or 0 (indicating that the ping wasis successful). the exit code is stored in the variable "$?".

Okay, the simple answer to your question is to redirect stderr to stdout. as what Fredik Phil mentioned in the comments.

instead of:

ping_results=$(ping -c 4 -q google.com);

use:

 ping_results=$(ping -c 4 -q google.com 2>&1);

or something similar...

However, depending on what you're doing, it might be better to test if the exit code of the ping command was 1 (indicating that the ping ended in an error), or 0 (indicating that the ping was successful). the exit code is stored in the variable "$?".

Okay, the simple answer to your question is to redirect stderr to stdout. as what Fredik Phil mentioned in the comments.

instead of:

ping_results=$(ping -c 4 -q google.com);

use:

 ping_results=$(ping -c 4 -q google.com 2>&1);

or something similar...

However, depending on what you're doing, it might be better to test if the exit code of the ping command is 1 (indicating that the ping is ending in an error), or 0 (indicating that the ping is successful). the exit code is stored in the variable "$?".

Source Link
pepper
  • 2.2k
  • 5
  • 27
  • 32

Okay, the simple answer to your question is to redirect stderr to stdout. as what Fredik Phil mentioned in the comments.

instead of:

ping_results=$(ping -c 4 -q google.com);

use:

 ping_results=$(ping -c 4 -q google.com 2>&1);

or something similar...

However, depending on what you're doing, it might be better to test if the exit code of the ping command was 1 (indicating that the ping ended in an error), or 0 (indicating that the ping was successful). the exit code is stored in the variable "$?".