Bash parameter expansion can't match spaces in variables like $* and $@How do I iterate over a range of numbers defined by variables in Bash?How to trim whitespace from a Bash variable?Assigning default values to shell variables with a single command in bashHow to check if a variable is set in Bash?How to concatenate string variables in BashHow to set a variable to the output of a command in Bash?Passing parameters to a Bash functionMake a Bash alias that takes a parameter?Bash empty array expansion with `set -u`Expansion of variable inside single quotes in a command in Bash
Is "remove commented out code" correct English?
How could indestructible materials be used in power generation?
Can a virus destroy the BIOS of a modern computer?
Apex Framework / library for consuming REST services
Bullying boss launched a smear campaign and made me unemployable
How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)
Valid term from quadratic sequence?
In 'Revenger,' what does 'cove' come from?
Is this a hacking script in function.php?
iPad being using in wall mount battery swollen
Expand and Contract
Could the museum Saturn V's be refitted for one more flight?
How badly should I try to prevent a user from XSSing themselves?
Would Slavery Reparations be considered Bills of Attainder and hence Illegal?
How to add frame around section using titlesec?
Which is the best way to check return result?
Madden-Julian Oscillation (MJO) - How to interpret the index?
Arrow those variables!
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
One verb to replace 'be a member of' a club
Unlock My Phone! February 2018
Can my sorcerer use a spellbook only to collect spells and scribe scrolls, not cast?
What mechanic is there to disable a threat instead of killing it?
Should I tell management that I intend to leave due to bad software development practices?
Bash parameter expansion can't match spaces in variables like $* and $@
How do I iterate over a range of numbers defined by variables in Bash?How to trim whitespace from a Bash variable?Assigning default values to shell variables with a single command in bashHow to check if a variable is set in Bash?How to concatenate string variables in BashHow to set a variable to the output of a command in Bash?Passing parameters to a Bash functionMake a Bash alias that takes a parameter?Bash empty array expansion with `set -u`Expansion of variable inside single quotes in a command in Bash
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.)
bash shell parameter-expansion
|
show 4 more comments
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.)
bash shell parameter-expansion
1
As I read pubs.opengroup.org/onlinepubs/9699919799/utilities/…: If parameter is#,*, or@, the result of the expansion is unspecified. -- so both are equally correct, and a script that wants to work on all POSIX platforms shouldn't rely on either behavior. (var=$*and$var// /<SPACE>, and you're set).
– Charles Duffy
Mar 8 at 22:36
@CharlesDuffy - Err... Um.. isn't$var// /<SPACE>parameter expansion with substring replacement .. a bashism? POSIX only provides suffix and prefix removal as I read it.
– David C. Rankin
Mar 8 at 23:12
@DavidC.Rankin, quite right. Still, the point thatvar=$*avoids relying on undefined behavior stands.
– Charles Duffy
Mar 8 at 23:14
@DavidC.Rankin – This is a bash question, so the bashism is okay ... though I was usingvar="$*"; echo "$var#x "to the same effect because I so rarely script in bash and I try to limit my bash scripts' bashisms to where they're absolutely necessary.
– Adam Katz
Mar 8 at 23:15
Agreed, I was just confused by your apparent use ofdash.
– David C. Rankin
Mar 8 at 23:15
|
show 4 more comments
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.)
bash shell parameter-expansion
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.)
bash shell parameter-expansion
bash shell parameter-expansion
edited Mar 8 at 22:42
Adam Katz
asked Mar 8 at 22:18
Adam KatzAdam Katz
6,22713756
6,22713756
1
As I read pubs.opengroup.org/onlinepubs/9699919799/utilities/…: If parameter is#,*, or@, the result of the expansion is unspecified. -- so both are equally correct, and a script that wants to work on all POSIX platforms shouldn't rely on either behavior. (var=$*and$var// /<SPACE>, and you're set).
– Charles Duffy
Mar 8 at 22:36
@CharlesDuffy - Err... Um.. isn't$var// /<SPACE>parameter expansion with substring replacement .. a bashism? POSIX only provides suffix and prefix removal as I read it.
– David C. Rankin
Mar 8 at 23:12
@DavidC.Rankin, quite right. Still, the point thatvar=$*avoids relying on undefined behavior stands.
– Charles Duffy
Mar 8 at 23:14
@DavidC.Rankin – This is a bash question, so the bashism is okay ... though I was usingvar="$*"; echo "$var#x "to the same effect because I so rarely script in bash and I try to limit my bash scripts' bashisms to where they're absolutely necessary.
– Adam Katz
Mar 8 at 23:15
Agreed, I was just confused by your apparent use ofdash.
– David C. Rankin
Mar 8 at 23:15
|
show 4 more comments
1
As I read pubs.opengroup.org/onlinepubs/9699919799/utilities/…: If parameter is#,*, or@, the result of the expansion is unspecified. -- so both are equally correct, and a script that wants to work on all POSIX platforms shouldn't rely on either behavior. (var=$*and$var// /<SPACE>, and you're set).
– Charles Duffy
Mar 8 at 22:36
@CharlesDuffy - Err... Um.. isn't$var// /<SPACE>parameter expansion with substring replacement .. a bashism? POSIX only provides suffix and prefix removal as I read it.
– David C. Rankin
Mar 8 at 23:12
@DavidC.Rankin, quite right. Still, the point thatvar=$*avoids relying on undefined behavior stands.
– Charles Duffy
Mar 8 at 23:14
@DavidC.Rankin – This is a bash question, so the bashism is okay ... though I was usingvar="$*"; echo "$var#x "to the same effect because I so rarely script in bash and I try to limit my bash scripts' bashisms to where they're absolutely necessary.
– Adam Katz
Mar 8 at 23:15
Agreed, I was just confused by your apparent use ofdash.
– David C. Rankin
Mar 8 at 23:15
1
1
As I read pubs.opengroup.org/onlinepubs/9699919799/utilities/…: If parameter is
#, *, or @, the result of the expansion is unspecified. -- so both are equally correct, and a script that wants to work on all POSIX platforms shouldn't rely on either behavior. (var=$* and $var// /<SPACE>, and you're set).– Charles Duffy
Mar 8 at 22:36
As I read pubs.opengroup.org/onlinepubs/9699919799/utilities/…: If parameter is
#, *, or @, the result of the expansion is unspecified. -- so both are equally correct, and a script that wants to work on all POSIX platforms shouldn't rely on either behavior. (var=$* and $var// /<SPACE>, and you're set).– Charles Duffy
Mar 8 at 22:36
@CharlesDuffy - Err... Um.. isn't
$var// /<SPACE> parameter expansion with substring replacement .. a bashism? POSIX only provides suffix and prefix removal as I read it.– David C. Rankin
Mar 8 at 23:12
@CharlesDuffy - Err... Um.. isn't
$var// /<SPACE> parameter expansion with substring replacement .. a bashism? POSIX only provides suffix and prefix removal as I read it.– David C. Rankin
Mar 8 at 23:12
@DavidC.Rankin, quite right. Still, the point that
var=$* avoids relying on undefined behavior stands.– Charles Duffy
Mar 8 at 23:14
@DavidC.Rankin, quite right. Still, the point that
var=$* avoids relying on undefined behavior stands.– Charles Duffy
Mar 8 at 23:14
@DavidC.Rankin – This is a bash question, so the bashism is okay ... though I was using
var="$*"; echo "$var#x " to the same effect because I so rarely script in bash and I try to limit my bash scripts' bashisms to where they're absolutely necessary.– Adam Katz
Mar 8 at 23:15
@DavidC.Rankin – This is a bash question, so the bashism is okay ... though I was using
var="$*"; echo "$var#x " to the same effect because I so rarely script in bash and I try to limit my bash scripts' bashisms to where they're absolutely necessary.– Adam Katz
Mar 8 at 23:15
Agreed, I was just confused by your apparent use of
dash.– David C. Rankin
Mar 8 at 23:15
Agreed, I was just confused by your apparent use of
dash.– David C. Rankin
Mar 8 at 23:15
|
show 4 more comments
1 Answer
1
active
oldest
votes
For array-like operands, the string operation is applied for each element before they are joined on spaces. Therefore, you can't apply them to the joining space.
Here's an example showing this:
$ set -- hello world "hello world with spaces"
$ echo "$*// /<SPACE>"
hello world hello<SPACE>world<SPACE>with<SPACE>spaces
Spaces within each argument is replaced just fine, but the spaces between them as inserted by $* are not affected.
The workaround is indeed a temporary variable.
Ah, nice demonstration.echo "<$*#hello >"(using yoursetline) better fits what I'm doing, and sure enough it gives me<hello world world with spaces>because of the implicit for each that you noted.
– Adam Katz
Mar 8 at 22:37
3
If your real question is "How do I concatenate all arguments except the first one?" then the answer is"$*:2"
– that other guy
Mar 8 at 22:41
Actually, yes: that's the literal answer to my (oversimplified) question, though I think your first paragraph and Charles Duffy's comment to the question combine for a more informative answer. (Also, I had a whole bunch of conditionals like[ "$*" != "$*#* foo* bar" ]which I've had to convert tocasepatterns like( * foo* bar* )but that didn't make it to the simplified question I asked here.)
– Adam Katz
Mar 8 at 22:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071780%2fbash-parameter-expansion-cant-match-spaces-in-variables-like-and%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
For array-like operands, the string operation is applied for each element before they are joined on spaces. Therefore, you can't apply them to the joining space.
Here's an example showing this:
$ set -- hello world "hello world with spaces"
$ echo "$*// /<SPACE>"
hello world hello<SPACE>world<SPACE>with<SPACE>spaces
Spaces within each argument is replaced just fine, but the spaces between them as inserted by $* are not affected.
The workaround is indeed a temporary variable.
Ah, nice demonstration.echo "<$*#hello >"(using yoursetline) better fits what I'm doing, and sure enough it gives me<hello world world with spaces>because of the implicit for each that you noted.
– Adam Katz
Mar 8 at 22:37
3
If your real question is "How do I concatenate all arguments except the first one?" then the answer is"$*:2"
– that other guy
Mar 8 at 22:41
Actually, yes: that's the literal answer to my (oversimplified) question, though I think your first paragraph and Charles Duffy's comment to the question combine for a more informative answer. (Also, I had a whole bunch of conditionals like[ "$*" != "$*#* foo* bar" ]which I've had to convert tocasepatterns like( * foo* bar* )but that didn't make it to the simplified question I asked here.)
– Adam Katz
Mar 8 at 22:50
add a comment |
For array-like operands, the string operation is applied for each element before they are joined on spaces. Therefore, you can't apply them to the joining space.
Here's an example showing this:
$ set -- hello world "hello world with spaces"
$ echo "$*// /<SPACE>"
hello world hello<SPACE>world<SPACE>with<SPACE>spaces
Spaces within each argument is replaced just fine, but the spaces between them as inserted by $* are not affected.
The workaround is indeed a temporary variable.
Ah, nice demonstration.echo "<$*#hello >"(using yoursetline) better fits what I'm doing, and sure enough it gives me<hello world world with spaces>because of the implicit for each that you noted.
– Adam Katz
Mar 8 at 22:37
3
If your real question is "How do I concatenate all arguments except the first one?" then the answer is"$*:2"
– that other guy
Mar 8 at 22:41
Actually, yes: that's the literal answer to my (oversimplified) question, though I think your first paragraph and Charles Duffy's comment to the question combine for a more informative answer. (Also, I had a whole bunch of conditionals like[ "$*" != "$*#* foo* bar" ]which I've had to convert tocasepatterns like( * foo* bar* )but that didn't make it to the simplified question I asked here.)
– Adam Katz
Mar 8 at 22:50
add a comment |
For array-like operands, the string operation is applied for each element before they are joined on spaces. Therefore, you can't apply them to the joining space.
Here's an example showing this:
$ set -- hello world "hello world with spaces"
$ echo "$*// /<SPACE>"
hello world hello<SPACE>world<SPACE>with<SPACE>spaces
Spaces within each argument is replaced just fine, but the spaces between them as inserted by $* are not affected.
The workaround is indeed a temporary variable.
For array-like operands, the string operation is applied for each element before they are joined on spaces. Therefore, you can't apply them to the joining space.
Here's an example showing this:
$ set -- hello world "hello world with spaces"
$ echo "$*// /<SPACE>"
hello world hello<SPACE>world<SPACE>with<SPACE>spaces
Spaces within each argument is replaced just fine, but the spaces between them as inserted by $* are not affected.
The workaround is indeed a temporary variable.
edited Mar 8 at 22:32
answered Mar 8 at 22:26
that other guythat other guy
75k886124
75k886124
Ah, nice demonstration.echo "<$*#hello >"(using yoursetline) better fits what I'm doing, and sure enough it gives me<hello world world with spaces>because of the implicit for each that you noted.
– Adam Katz
Mar 8 at 22:37
3
If your real question is "How do I concatenate all arguments except the first one?" then the answer is"$*:2"
– that other guy
Mar 8 at 22:41
Actually, yes: that's the literal answer to my (oversimplified) question, though I think your first paragraph and Charles Duffy's comment to the question combine for a more informative answer. (Also, I had a whole bunch of conditionals like[ "$*" != "$*#* foo* bar" ]which I've had to convert tocasepatterns like( * foo* bar* )but that didn't make it to the simplified question I asked here.)
– Adam Katz
Mar 8 at 22:50
add a comment |
Ah, nice demonstration.echo "<$*#hello >"(using yoursetline) better fits what I'm doing, and sure enough it gives me<hello world world with spaces>because of the implicit for each that you noted.
– Adam Katz
Mar 8 at 22:37
3
If your real question is "How do I concatenate all arguments except the first one?" then the answer is"$*:2"
– that other guy
Mar 8 at 22:41
Actually, yes: that's the literal answer to my (oversimplified) question, though I think your first paragraph and Charles Duffy's comment to the question combine for a more informative answer. (Also, I had a whole bunch of conditionals like[ "$*" != "$*#* foo* bar" ]which I've had to convert tocasepatterns like( * foo* bar* )but that didn't make it to the simplified question I asked here.)
– Adam Katz
Mar 8 at 22:50
Ah, nice demonstration.
echo "<$*#hello >" (using your set line) better fits what I'm doing, and sure enough it gives me <hello world world with spaces> because of the implicit for each that you noted.– Adam Katz
Mar 8 at 22:37
Ah, nice demonstration.
echo "<$*#hello >" (using your set line) better fits what I'm doing, and sure enough it gives me <hello world world with spaces> because of the implicit for each that you noted.– Adam Katz
Mar 8 at 22:37
3
3
If your real question is "How do I concatenate all arguments except the first one?" then the answer is
"$*:2"– that other guy
Mar 8 at 22:41
If your real question is "How do I concatenate all arguments except the first one?" then the answer is
"$*:2"– that other guy
Mar 8 at 22:41
Actually, yes: that's the literal answer to my (oversimplified) question, though I think your first paragraph and Charles Duffy's comment to the question combine for a more informative answer. (Also, I had a whole bunch of conditionals like
[ "$*" != "$*#* foo* bar" ] which I've had to convert to case patterns like ( * foo* bar* ) but that didn't make it to the simplified question I asked here.)– Adam Katz
Mar 8 at 22:50
Actually, yes: that's the literal answer to my (oversimplified) question, though I think your first paragraph and Charles Duffy's comment to the question combine for a more informative answer. (Also, I had a whole bunch of conditionals like
[ "$*" != "$*#* foo* bar" ] which I've had to convert to case patterns like ( * foo* bar* ) but that didn't make it to the simplified question I asked here.)– Adam Katz
Mar 8 at 22:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071780%2fbash-parameter-expansion-cant-match-spaces-in-variables-like-and%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
As I read pubs.opengroup.org/onlinepubs/9699919799/utilities/…: If parameter is
#,*, or@, the result of the expansion is unspecified. -- so both are equally correct, and a script that wants to work on all POSIX platforms shouldn't rely on either behavior. (var=$*and$var// /<SPACE>, and you're set).– Charles Duffy
Mar 8 at 22:36
@CharlesDuffy - Err... Um.. isn't
$var// /<SPACE>parameter expansion with substring replacement .. a bashism? POSIX only provides suffix and prefix removal as I read it.– David C. Rankin
Mar 8 at 23:12
@DavidC.Rankin, quite right. Still, the point that
var=$*avoids relying on undefined behavior stands.– Charles Duffy
Mar 8 at 23:14
@DavidC.Rankin – This is a bash question, so the bashism is okay ... though I was using
var="$*"; echo "$var#x "to the same effect because I so rarely script in bash and I try to limit my bash scripts' bashisms to where they're absolutely necessary.– Adam Katz
Mar 8 at 23:15
Agreed, I was just confused by your apparent use of
dash.– David C. Rankin
Mar 8 at 23:15