Are you sure echo gets 2 parameters in echo $X ? For me, he gets 3. Let's try:
X="'ab' 'c'" function f(){ echo $#; echo $1; echo $2; echo $3; } f $X
displayed:
3 'a b' 'c'
3 parameters: 'a , b' and 'c' . I do not think this is what you expect.
If you want to create a multi-parameter variable, set IFS to char, which you will not use (possibly | ), and use it as a parameter separator in your variable:
X="ab|c" IFS="|" function f(){ echo $#; echo $1; echo $2; } f $X
source share