Last active
October 2, 2024 08:53
-
-
Save iolloyd/8e0be994e1396b21d9ac9f0d19cd8d58 to your computer and use it in GitHub Desktop.
file_or_pipe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to process input (file or stdin) | |
process_input() { | |
while IFS= read -r line; do | |
# Perform any processing here | |
echo "$line" | |
done | |
} | |
# Main logic | |
if [ $# -gt 0 ]; then | |
# If arguments are provided, process each file | |
for file in "$@"; do | |
if [ -f "$file" ]; then | |
process_input < "$file" | |
else | |
echo "Error: File '$file' does not exist." >&2 | |
fi | |
done | |
else | |
# If no arguments, process stdin | |
process_input | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
removed duplication of read block