Дана 24/05/12 07:31PM, Alexis написа:
> i wondered about that in this context. If people putting odd / inappropriate
> things in directory names are a concern ("weird characters", as you wrote
> upthread), what do we do about the possibility of someone having consciously
> put e.g. a \t in a directory name because they were assuming that it _would_
> get interpreted when required?
Omitting -r as a parameter to read would make it interpret backscape
sequences, which would make the directory name in the filesystem
different than the one command/script operates on, which is most
likely undesired (unless the intention is to exploit some bug).
Consider
$ dir=$'hello\\\\e[1mworld\\\\e[0m'; echo $dir | while read dir; do
echo $dir; mkdir $dir; done
helloe[1mworlde[0m
$ ls -ldq hello*
drwxr-xr-x 2 user user 512 May 12 14:13 helloe[1mworlde[0m/
$ ls -ld $(echo $dir)
ls: hello\e[1mworld\e[0m: No such file or directory
$ rmdir $(echo $dir)
rmdir: hello\e[1mworld\e[0m: No such file or directory
$ rmdir helloe\[1mworlde\[0m/
^^^^^^^^^^^^^^^^-- expansion by Tab key
vs
$ dir=$'hello\\\\e[1mworld\\\\e[0m'; echo $dir | while read -r dir; do
echo $dir; mkdir $dir; done
helloworld
^^^^^-- bold attribute on
$ ls -ldq hello*
drwxr-xr-x 2 user user 512 May 12 14:13 hello\e[1mworld\e[0m/
$ ls -ld $(echo $dir)
drwxr-xr-x 2 user user 512 May 12 14:13 hello\e[1mworld\e[0m/
$ rmdir $(echo $dir)