Differences between revisions 2 and 4 (spanning 2 versions)
Revision 2 as of 2023-01-20 17:27:43
Size: 317
Comment:
Revision 4 as of 2023-01-20 17:34:47
Size: 800
Comment:
Deletions are marked like this. Additions are marked like this.
Line 10: Line 10:

{{{
if [ TEST ]; then
  echo "TEST is true"
elif grep /path/to/file --fixed-strings foo >/dev/null; then
  echo "TEST is false and '/path/to/file' contains 'foo'"
else
  echo "TEST is false and '/path/to/file' does not contain 'foo'"
fi
}}}

[[Shell/Test|Shell tests]] are typically used as the condition (as seen above), but any command that sets the exit code in the expected pattern (zero for true, non-zero for false; as seen above with `grep(1)`) can be used.
Line 26: Line 38:
    echo "Please enter y or n"     echo "Please enter y or n only"

Shell Logic


Conditional Logic

if [ TEST ]; then
  echo "TEST is true"
elif grep /path/to/file --fixed-strings foo >/dev/null; then
  echo "TEST is false and '/path/to/file' contains 'foo'"
else
  echo "TEST is false and '/path/to/file' does not contain 'foo'"
fi

Shell tests are typically used as the condition (as seen above), but any command that sets the exit code in the expected pattern (zero for true, non-zero for false; as seen above with grep(1)) can be used.


Case Switching Logic

case $INPUT_STRING in
  y)
    echo "Proceeding..."
    ;;
  n)
    echo "Quitting..."
    ;;
  *)
    echo "Please enter y or n only"
    ;;
esac


CategoryRicottone

Shell/Logic (last edited 2023-01-20 22:05:53 by DominicRicottone)