8

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?

0

2 Answers 2

15

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:

  • occurrences of wildcards (? = any single character and * = any number of characters)
  • ranges enclosed in square brackets (e.g. [a-z12] = any character from a to z, or 1 or 2)
  • non matching lists (e.g. [^a-z] = any character not in the range a to z)
  • and character classes (e.g. [[: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??
2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .