Write a bash script to fail a command when the command outputs a certain string or pattern. The script accepts 2 arguments: a child command as an argument, and a list of strings to scan STDOUT/STDERR for as the other arguments. It then invokes the child command. Store the exit status of the child command. Then, compare the output of the child command and search for the given text pattern(s). If the pattern is matched, exit 1. Otherwise, exit the child command exit status.
user
Sure, I can help you write such a script. Here's a basic example using Bash:

```bash
#!/bin/bash

if [ $# -lt 2 ]; then
  echo "Usage: $0 <command> <pattern1> [<pattern2> ...]"
  exit 1
fi

command="$1"
shift
patterns=("$@")

# Invoke the command and store the exit status
exit_status=$?

# Check for the specified pattern in the standard output and error streams
if grep -q "$1" "$2"; then
  echo "Pattern \"$1\" found in the output!"
  exit 1
elif grep -q "$1" "$2"; then
  echo "Pattern \"$1\" found in the error!"
  exit 1
fi

# Check for remaining patterns
for pattern in "${patterns[@]}"; do
  if grep -q "$pattern" "$2"; then
    echo "Pattern \"$pattern\" found in the error!"
    exit 1
  fi
done

echo "Command exited with status $exit_status."
exit "$exit_status"
```

This script expects the first argument to be the command to be run, followed by one or more patterns to look for in the standard output (`$2`) and error (`$3`) streams. It will search for each pattern in the STDERR as well, if it appears in the last argument.

You can save this script as a `.sh` file, make it executable (`chmod +x filename.sh`), and run it with the command you want to run, followed by the pattern or patterns to search:

```bash
./filename.sh "ls -l /tmp" foo bar
```

This would invoke the `ls -l` command on `/tmp`, search for both the "foo" and "bar" patterns in the STDERR, and output either "Pattern X found in the output!" or "Pattern X found in the error!". The command's exit status is stored in the `$?` variable, and printed at the end.
assistant
Write a bash script to fail a command when the command outputs a certain string or pattern. The script accepts 2 arguments: a child command as an argument, and a list of strings to scan STDOUT/STDERR for as the other arguments. It then invokes the child command. Store the exit status of the child command. Then, compare the output of the child command and search for the given text pattern(s). If the pattern is matched, exit 1. Otherwise, exit the child command exit status.
user
Here's a bash script that meets your requirements:

```bash
#!/bin/bash

# Check if the correct number of arguments are provided
if [ "$#" -lt 2 ]; then
  echo "Usage: $0 <command> <pattern1> [<pattern2> ...]"
  exit 1
fi

# Extract the command and patterns from the arguments
command="$1"
shift
patterns=("$@")

# Run the command and capture the output and exit status
output=$($command 2>&1)
command_exit_status=$?

# Search for the patterns in the output
for pattern in "${patterns[@]}"; do
  if echo "$output" | grep -q "$pattern"; then
    echo "Pattern '$pattern' found in the command output."
    exit 1
  fi
done

# Exit with the command's exit status if no pattern is found
exit $command_exit_status
```

Usage:

```sh
$ ./fail_on_pattern.sh "ls -l /nonexistent_folder" "No such file or directory"
Pattern 'No such file or directory' found in the command output.

$ echo $?
1
```
assistant