I am wanting to execute a command with arguments read in from a file. This works fine, until 1 of the arguments needs to have a space.
I have tried grouping the words with quotes and backslashes, but neither have worked.
The functionality I am after is exactly what xargs does, except I need to call a function rather than a command as it relies on other variables set up elsewhere in the script
script:
do_echo() {
echo '$1:' $1
echo '$2:' $2
}
line=`cat input.txt` #cat used for simplicity, can have more than 1 line
do_echo $line
input.txt:
"hello world" "hello back"
Expected result:
$1: hello world
$2: hello back
Observed result:
$1: "hello
$2: world"
EDIT:
I am using this to execute the same command multiple times with different inputs. There is up to 15 parameters per line, and could be upwards of 50 lines.
A tabular format would be ideal, although the current answer of putting each parameter on a line will work.
do_echo "$line"provide different results thando_echo $line?