Created
December 17, 2024 15:59
-
-
Save marcogrcr/2bfa23ea164bc7542e70d99045c2ba14 to your computer and use it in GitHub Desktop.
Executes code for each line of a file
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/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