#!/bin/bash
# filter-safe-shell-commands-by-success: Filter shell commands by success.

# WARNING: This script is not safe for untrusted input.

# This script will read from stdin and execute each line as a shell command.
# If the command succeeds, it will be echoed to stdout.
# If the command fails, it will be echoed to stderr.
# This script is useful for filtering a list of shell commands to only those
# that succeed, such as a list from bash history.

while read A; do
    if echo "$A" | q bash; then
        echo "$A"
    else
        echo >&2 "$A"
    fi
done
