Sujet : Re: Long filenames in DOS/Windows and Unix/Linux
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.programmerDate : 10. Sep 2024, 06:17:48
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbokpu$2ptqu$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 05.09.2024 11:29, Ralf Fassel wrote:
* Richard Kettlewell <invalid@invalid.invalid>
| Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
| > [...] For example, I might type something like:
| >
| > for file in * ; do cp -p $file $file.bak ; done
Quoting is generally the standard way to be on the safe side...
for file in * ; do cp -p "$file" "$file.bak" ; done
| That’s the heart of the matter. Field splitting happens after parameter
| expansion.
Only sometimes it doesn't :-)
$ foo="foo bar"
$ bar=$foo
No problem with the space in the expanded value here!
$ echo $bar
foo bar
There is a problem also with 'echo'...!
space="foo bar"
two_spaces="two spaces"
a_tab="a tab"
# all the IFSs get collapsed in:
echo $space
echo $two_spaces
echo $a_tab
# correct way to handle that:
echo "$space"
echo "$two_spaces"
echo "$a_tab"
but of course:
ls $bar
ls: cannot access 'foo': No such file or directory
ls: cannot access 'bar': No such file or directory
It's documented in bash(1):
PARAMETERS
[...]
A variable may be assigned to by a statement of the form
name=[value]
[...] Word splitting is not performed, with the exception of
"$@" as explained below under Special Parameters.
but I find it confusing nevertheless.
It's not that confusing if you know the difference between a shell
construct (that doesn't require quotes) and "the all rest" that
needs (for the general case) quotes. If in doubt there's the rule
of thumb to always use quotes.
Janis
R'