Last active
April 23, 2020 07:51
-
-
Save fumiyas/d8a9a9b1771b633858764b8decb3c615 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 | |
## | |
## Pass LSV (Line-separated values) to a command | |
## | |
LF=' | |
' | |
samplecmd() { | |
for x; do | |
echo "<<$x>>" | |
done | |
} | |
run_cmd_with_word_splitting_arg() { | |
local cmd="$1"; shift | |
local arg="$1"; shift | |
local shopts="$-" | |
set -f | |
"$cmd" $arg | |
local rc="$?" | |
[ -n "${shopts##*f*}" ] && set +f | |
return "$rc" | |
} | |
run_cmd_with_lsv() { | |
local cmd="$1"; shift | |
local lsv="$1"; shift | |
IFS="$LF" run_cmd_with_word_splitting_arg "$cmd" "$lsv" | |
} | |
lsv='aaa | |
bbb ccc | |
* | |
?' | |
run_cmd_with_lsv samplecmd "$lsv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment