For each command on each line in a text file, it outputs the name of the command and the output of the command. It echoes this so you can pipe the output elsewhere.
#!/bin/bash | |
i=0 | |
# File input | |
FILE1=$1 | |
# Final output | |
OUTPUT="" | |
# Loop over all lines in text | |
while IFS= read -r line | |
do | |
# Evaluate command | |
COMMANDOUTPUT=`eval $line` | |
# Check for whether to concatenate with newline at start or not | |
if [ $i -eq 0 ] | |
then | |
OUTPUT="$line\n"$COMMANDOUTPUT | |
i=1 | |
else | |
OUTPUT=$OUTPUT"\n$line\n"$COMMANDOUTPUT | |
fi | |
done < "$FILE1" | |
# Output can be piped. -e parameter makes \n recognized | |
echo -e $OUTPUT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment