I'm trying to pass a string to a function. The string contains multiple arguments and some of the arguments may begin with multiple spaces.
#!/bin/bash
test_function() {
echo "arg1 is: '$1'"
echo "arg2 is: '$2'"
echo "arg3 is: '$3'"
}
a_string="one two \" string with spaces in front\""
result=$(test_function $a_string)
echo "$result"
Here is the output actually produced:
arg1 is: 'one'
arg2 is: 'two'
arg3 is: '"'
Here is an example of the output I am trying to achieve:
arg1 is: 'one'
arg2 is: 'two'
arg3 is: ' string with spaces in front'
How can I store arguments containing spaces in a string like this to later be passed to a function?
Although it can be done with an array, I need to first convert the string into the array values.