66 lines
1.7 KiB
Bash
Executable File
66 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Script: show
|
|
# Purpose: Reads commands line-by-line from a specified file (defaulting to 'show-it.txt')
|
|
# and executes each one.
|
|
|
|
# --- Configuration ---
|
|
COMMAND_FILE="${1:-show-it}"
|
|
SKIP_COMMENT_LINES=true
|
|
PAUSE_MARKER="---PAUSE---"
|
|
|
|
# --- Execution ---
|
|
|
|
# Check if the command file exists
|
|
if [ ! -f "$COMMAND_FILE" ]; then
|
|
echo "Error: Command file not found at '$COMMAND_FILE'" >&2
|
|
exit 1
|
|
fi
|
|
|
|
#echo "--- START: Executing commands from $COMMAND_FILE ---"
|
|
|
|
# Read the file line by line
|
|
while IFS= read -r command_line
|
|
do
|
|
# Trim leading and trailing whitespace
|
|
command_line=$(echo "$command_line" | xargs)
|
|
|
|
# Skip empty lines
|
|
if [ -z "$command_line" ]; then
|
|
continue
|
|
fi
|
|
|
|
# Check for the pause marker
|
|
if [ "$command_line" = "$PAUSE_MARKER" ]; then
|
|
#echo ""
|
|
#echo "========== PAUSE =========="
|
|
# Wait for the user to press ENTER, reading explicitly from the terminal
|
|
read -r -p "waiting... (press enter)" < /dev/tty
|
|
#echo "==========================="
|
|
continue
|
|
fi
|
|
|
|
# Skip lines starting with # if enabled (no logging for cleaner output)
|
|
if $SKIP_COMMENT_LINES && [[ "$command_line" =~ ^# ]]; then
|
|
continue
|
|
fi
|
|
|
|
# --- Less Verbose Execution Block ---
|
|
#echo ""
|
|
# Print the command line clearly before execution
|
|
#echo "\$ $command_line"
|
|
|
|
# Execute the command line
|
|
eval "$command_line"
|
|
|
|
# Only report non-zero (failure) exit status
|
|
EXIT_STATUS=$?
|
|
if [ $EXIT_STATUS -ne 0 ]; then
|
|
echo "!!! COMMAND FAILED (Status $EXIT_STATUS) !!!" >&2
|
|
fi
|
|
# --- End Execution Block ---
|
|
|
|
done < "$COMMAND_FILE"
|
|
|
|
#echo ""
|
|
#echo "--- END: Script execution complete ---" |