Created
January 12, 2015 19:21
-
-
Save paulp/4985c5dff0c6fe5d36c3 to your computer and use it in GitHub Desktop.
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 | |
# | |
# e.g. mkString : a b c becomes a:b:c | |
# A single separator argument means the strings to join are on stdin. | |
# | |
# mkString "\n" < /some/file does get the newline | |
# through the obstacle course. | |
mkString () { | |
local sep="$1" | |
local first=1 | |
while read line; do | |
if (( $first )); then | |
first=0 | |
printf "%s" "$line" | |
else | |
printf "${sep}%s" "$line" | |
fi | |
done | |
echo "" | |
} | |
if [[ $# -gt 1 ]]; then | |
sep="$1" && shift && ( IFS="$sep" ; echo "$*"; ) | |
else | |
mkString "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment