Skip to content

Instantly share code, notes, and snippets.

@fumiyas
Last active April 23, 2020 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumiyas/d8a9a9b1771b633858764b8decb3c615 to your computer and use it in GitHub Desktop.
Save fumiyas/d8a9a9b1771b633858764b8decb3c615 to your computer and use it in GitHub Desktop.
#!/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