6

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?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
elbarna
  • 12,050
  • 22
  • 92
  • 170

2 Answers2

14

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??
jlliagre
  • 60,319
  • 10
  • 115
  • 157
1

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.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936