2013/8/11 Bernhard Voelker <mail@bernhard-voelker.de>:
On 08/11/2013 11:04 PM, Ciro Iriarte wrote:
Hi!, anybody can tell me why using "[]" sustitution for file listing works
That's because of shell globbing.
ciro@roamer:/tmp> ls -ld [123]b drwxr-xr-x 2 ciro users 4096 ago 10 16:22 1b drwxr-xr-x 2 ciro users 4096 ago 10 16:22 2b drwxr-xr-x 2 ciro users 4096 ago 10 16:22 3b
Here, the files 1b, 2b, 3b exist, so the shell can glob them and pass them to ls(1).
But for file creation it doesn't?
ciro@roamer:/tmp/bash> mkdir [123]dir ciro@roamer:/tmp/bash> touch [123].file ciro@roamer:/tmp/bash> ls -l total 4 drwxr-xr-x 2 ciro users 4096 ago 11 17:04 [123]dir -rw-r--r-- 1 ciro users 0 ago 11 17:04 [123].file
Here, the glob pattern (incidentally!) doesn't match a glob because the files didn't exist yet. Therefore, the shell passes them as string to mkdir(1) and touch(1).
In the case you're unsure, try adding "echo" in front of the commands. By this, you'll see what the shall will pass to the commands. In your case, it should look like that:
$ echo ls -ld [123]b ls -ld 1b 2b 3b
$ echo mkdir [123]dir mkdir [123]dir
Have a nice day, Berny
Thanks Berny, but why [] doesn't work in both cases like {}?, {} works for file listing and for file creation... That's why I was expecting [] to work the same way (my bad?) Regards, -- Ciro Iriarte http://cyruspy.wordpress.com -- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org