[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: shell scripts, spaces, and backslashes
From: |
Chet Ramey |
Subject: |
Re: shell scripts, spaces, and backslashes |
Date: |
Sat, 12 Oct 2024 15:24:13 -0400 |
User-agent: |
Mozilla Thunderbird |
On 10/11/24 3:41 PM, Bruno Haible wrote:
Hi Chet,
Hi, Bruno.
I wrote:
Stackoverflow [1] says that word-expansion must be
avoided, because it does not support the spaces in arguments
These two examples show how non-intuitive shell scripts behave,
regarding spaces and backslashes in arguments:
$ printf '%s\n' a\\bc\ d\\ef
a\bc d\ef
$ var='a\\bc\ d\\ef'
$ printf '%s\n' $var
a\\bc\
d\\ef
Good luck understanding this!
Word splitting and quote removal aren't that bad.
The inconsistency between these two examples, regarding word splitting
and quote removal, is only a minor problem, because it is easy to avoid it:
just
1. use double-quotes around every variable reference,
2. use `...` and $(...) only on the right-hand side of variable assignments.
Not quite worth the hyperbole, even if the workaround is straightforward.
I'm saying that word splitting and quote removal aren't that complicated,
the business of "IFS whitespace" included, if people take the time to
learn them.
The major problem (with POSIX sh) is that
Yes, the POSIX shell has only one built-in array: the positional
parameters. It could badly use even simple indexed arrays.
But this doesn't have much to do wth the original message, does it?
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature
- Re: csharpexec, csharpcomp: Add support for dotnet, (continued)
- Re: csharpexec, csharpcomp: Add support for dotnet, Simon Josefsson, 2024/10/09
- Re: csharpexec, csharpcomp: Add support for dotnet, Bruno Haible, 2024/10/09
- Re: csharpexec, csharpcomp: Add support for dotnet, Simon Josefsson, 2024/10/09
- Re: csharpexec, csharpcomp: Add support for dotnet, Bruno Haible, 2024/10/09
csharpcomp-script: Handle directories with spaces correctly, Bruno Haible, 2024/10/10
- shell scripts, spaces, and backslashes, Bruno Haible, 2024/10/11
- Re: shell scripts, spaces, and backslashes, Chet Ramey, 2024/10/11
- Re: shell scripts, spaces, and backslashes, Bruno Haible, 2024/10/11
- Re: shell scripts, spaces, and backslashes,
Chet Ramey <=