Skip to content

Instantly share code, notes, and snippets.

@marcogrcr
Created December 17, 2024 15:59
Show Gist options
  • Save marcogrcr/2bfa23ea164bc7542e70d99045c2ba14 to your computer and use it in GitHub Desktop.
Save marcogrcr/2bfa23ea164bc7542e70d99045c2ba14 to your computer and use it in GitHub Desktop.
Executes code for each line of a file
#!/bin/sh
# we use a heredoc for inliling the lines in the script, but they can be obtained from a file as well
# IMPORTANT: heredocs MUST use tabs, they cannot use space indentation
LINES=$(
cat <<- EOF
line1
line2
line3
EOF
)
# prints:
# -line1-
# -line3-
# -line3-
echo "$LINES" | while IFS= read -r LINE
do
echo "-$LINE-"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment