Mailinglist Archive: opensuse (880 mails)

< Previous Next >
Re: [opensuse] Back to the basics (bash)
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
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References