Using dash (0.5.10.2), I can do this:
% dash
$ set -- x hello world
$ echo "<${*#x }>"
<hello world>
This is the behavior I expect. The contents of $*
(which are x hello world
as assigned by set
and delimited by spaces) are run through shell parameter expansion to remove any leading x
for echo, thus resulting in hello world
, which I'm echoing with surrounding brackets to demonstrate the lack of surrounding white space.
I can't replicate that in bash (5.0.2(1)-release). It appears the space, a delimiter, is inaccessible:
% bash
$ set -- x hello world
$ echo "<${*#x }>"
<x hello world>
$ echo "<${@#x }>" # trying $@ instead of $*
<x hello world>
$ echo "<${*#x}>" # without the space works but now I have a space
< hello world>
$ echo "<${*#x?}>" # trying the `?` wildcard for a single character
<x hello world>
$ echo "<${*#x\ }>" # trying to escape the space
<x hello world>
$ echo "<${*/#x /}>" # using bash pattern substitution instead
<x hello world>
$ echo "<${*#x$IFS}>" # trying the input field separator variable
<x hello world>
Is there a solution here? Perhaps some way of modifying $*
or changing the output field separator?
My current workaround is to assign it to a temporary variable, but that's pretty ugly. (I need bash or else I'd stick with /bin/sh, which is dash.)