In the book "A guide to aix 3.2", it says that one may use the Korn Shell command set -f to "disable filename generation", but what does it mean?
What happens with set -f?
In the book "A guide to aix 3.2", it says that one may use the Korn Shell command set -f to "disable filename generation", but what does it mean?
What happens with set -f?
set -f is the portable (i.e. POSIX) way to disable filename expansion.
When enabled (by default or with set +f), filename expansion is an operation performed by the shell that replaces, when possible, command line arguments containing:
? = any single character and * = any number of characters)[a-z12] = any character from a to z, or 1 or 2)[^a-z] = any character not in the range a to z)[[:xdigit:]] = any character that can be used to represent an hexadecimal number)by the file names that match them.
When disabled, these arguments are left unchanged.
$ pwd
/etc/samba
$ echo *
lmhosts smb.conf
$ echo *o??
smb.conf
$ set -f
$ echo *
*
$ echo *o??
*o??
In both ksh and bash, the set -f command disables file name generation ("path name expansion"). It is equivalent to setting the noglob shell option (in both shells).
It prevents the shell from expanding file globbing patterns:
$ ls -l
total 0
-rw-r--r-- 1 kk kk 0 Dec 30 21:39 hello
-rw-r--r-- 1 kk kk 0 Dec 30 21:39 world
$ echo *l[a-k]
world
$ echo *
hello world
$ set -o noglob
$ echo *
*
$ echo *l[a-k]
*l[a-k]
To revert (clear) the setting, use either set +f or set +o noglob.