0

I tried to look up info on export and set using man and was surprised to see there is nothing. Is this true, or is this something distribution specific? Why is the page missing?

Usagi
  • 377

3 Answers3

1

These are both shell builtins, which you can check with:

$ type export
export is a shell builtin

So you can either use help export or man builtins.

m0dular
  • 1,261
1

These are internal functions provided by the shell, and not true standalone commands like those you find in /bin or /usr/bin. Compare the output of whereis ls to the one of whereis set or whereis export.

You can type help to have a list of all such internal commands, or look at the bash manual under SHELL BUILTIN COMMANDS section.

So, this is not distribution specific. Note that the list of available commands will depend on the shell used.

And sometimes you can have the same command as a shell builtin and as a command on the system, like pwd. The builtin takes precedence, and to override it you need to call the command like \pwd. You have to be careful of that when you need to maintain some scripts for multiple shells, especially if the syntax is not the same builtin the builtin and the external command.

  • So what does it mean when there is a built-in located in /bin? As is the case of pwd for me. When I "type pwd" it is described as a built-in but "whereis pwd" points to an executable in /bin. – Usagi Jun 29 '18 at 22:33
  • 1
    In this case it's both :) The one that will be executed when you run pwd is the builtin, which you can see from man pwd
       NOTE: your shell may have its own version of pwd, which usually supersedes the version
       described here.  Please refer to your shell's  documentation  for  details  about  the
       options it supports.
    
    – m0dular Jun 29 '18 at 22:38
  • 2
    It is a "name collision" :-) it happens, and can be unfortunate if you need compatibilities with multiple shells and if both commands do not have the same syntax. If you type pwd the builtin shell will have precedence. If you want the other command, that is NOT the builtin, you will need to use instead \pwd – Patrick Mevzek Jun 29 '18 at 22:50
0

These are built in commands to the shell. With Bourne shells you can use the help <cmd> to get usage details on how to use anything that's builtin.

set cmd

$ help set
set: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
    Set or unset values of shell options and positional parameters.

    Change the value of shell attributes and positional parameters, or
    display the names and values of shell variables.

    Options:
      -a  Mark variables which are modified or created for export.
      -b  Notify of job termination immediately.
      -e  Exit immediately if a command exits with a non-zero status.
      -f  Disable file name generation (globbing).
      -h  Remember the location of commands as they are looked up.
      -k  All assignment arguments are placed in the environment for a
          command, not just those that precede the command name.
      -m  Job control is enabled.
      -n  Read commands but do not execute them.
    ...
    ...

export cmd

$ help export
export: export [-fn] [name[=value] ...] or export -p
    Set export attribute for shell variables.

    Marks each NAME for automatic export to the environment of subsequently
    executed commands.  If VALUE is supplied, assign VALUE before exporting.

    Options:
      -f    refer to shell functions
      -n    remove the export property from each NAME
      -p    display a list of all exported variables and functions

    An argument of `--' disables further option processing.

    Exit Status:
    Returns success unless an invalid option is given or NAME is invalid.
slm
  • 369,824
  • help set on UNIX gives this result: ERROR: Key 'set' not found (he1), since help is part of the SCCS commands. On the other side, set and export have man pages on UNIX: http://schillix.sourceforge.net/man/man1/set.1.html – schily Jun 30 '18 at 08:42