Last active
August 29, 2015 14:02
-
-
Save cpburnz/164eeaee47877efed51a to your computer and use it in GitHub Desktop.
From a bash shell, store new-line separated strings into a variable, and execute a command for each line.
This file contains 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 | |
# | |
# From a bash shell, store new-line separated strings into a variable, and | |
# execute a command for each line. | |
# | |
# Author: Caleb P. Burns | |
# License: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication | |
# Version: 1.0.0 | |
# Enter new-line separated strings into $LINES. | |
read -rd '' LINES <<'EOF' | |
line 1 | |
line 2 | |
line 3 | |
line 4 | |
EOF | |
# Iterate over each line in $LINES, and do something with it. | |
# - NOTE: Do not double-quote $LINES; otherwise, it will be treated as one | |
# single line. | |
# - NOTE: Depending on the style of each line, you may want to double-quote | |
# $LINE. If $LINE is a single value with spaces, then you want to double | |
# quote it. | |
for LINE in $LINES; do echo "$LINE"; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment