Answer the question
In order to leave comments, you need to log in
bash function arguments with spaces from variable?
The question is confusing, in general, what happens to me is something like this
while read line || ;
do
l=$(echo "${line}")
lo_m "${loc_file}" ${line}
done < "${appname}.loc"
"string" "value vvv"
#!/bin/bash
myvar="\
\"str1\" \"var1 vvv\"
\"str2\" \"var2 www\""
echo "$myvar";
myfunc(){
echo "$1 :: $2 :: $3"
}
echo "$myvar" | while read -r line;
do
myfunc "str multi" $line
done
"str1" "var1 vvv"
"str2" "var2 www"
str multi :: "str1" :: "var1
str multi :: "str2" :: "var2
Answer the question
In order to leave comments, you need to log in
In the file you don't have different arguments, but just a string.
You pass it as a string and expect the read command to parse it into separate arguments.
But read doesn't do that.
The correct way is to use CSV files that will contain:
str1,var1 vvv
str2,var2 www
And then you can parse by commas (or take any other character that does not occur in your data as a separator)
while read; do
echo ${REPLY} | cut -d "," --output-delimiter ":" -f 1,2
done <<<'str1,var1 vvv
str2,var2 www'
while read; do
echo "${REPLY}" | cut -d "\"" --output-delimiter ":" -f 2,4
done <<<'"str1" "var1 vvv"
"str2" "var2 www"'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question