Skip to main content
added 19 characters in body
Source Link
ilkkachu
  • 141.4k
  • 16
  • 249
  • 418

export exportsmarks the given variable as exported to children of the current process, by default they are not exported. For example:

$ foo=bar
$ echo "$foo"
bar
$ bash -c 'echo "$foo"'

$ export foo
$ bash -c 'echo "$foo"'
bar

set, on the other hand, sets shell attributes, for example, and the positional parameters.

$ set foo=baz
$ echo "$1"
foo=baz

Note that baz is not assigned to foo, it simply becomes a literal positional parameter. There are many other things set can do (mostly shell options), see help set.

As for printing, export called with no arguments prints all of the variables in the shell's environment. set also prints variables that are not exported. It can also export some other objects (although you should note that this is not portable), see help export.

export exports to children of the current process, by default they are not exported. For example:

$ foo=bar
$ echo "$foo"
bar
$ bash -c 'echo "$foo"'

$ export foo
$ bash -c 'echo "$foo"'
bar

set, on the other hand, sets shell attributes, for example, the positional parameters.

$ set foo=baz
$ echo "$1"
foo=baz

Note that baz is not assigned to foo, it simply becomes a literal positional parameter. There are many other things set can do (mostly shell options), see help set.

As for printing, export called with no arguments prints all of the variables in the shell's environment. set also prints variables that are not exported. It can also export some other objects (although you should note that this is not portable), see help export.

export marks the given variable as exported to children of the current process, by default they are not exported. For example:

$ foo=bar
$ echo "$foo"
bar
$ bash -c 'echo "$foo"'

$ export foo
$ bash -c 'echo "$foo"'
bar

set, on the other hand, sets shell attributes and the positional parameters.

$ set foo=baz
$ echo "$1"
foo=baz

Note that baz is not assigned to foo, it simply becomes a literal positional parameter. There are many other things set can do (mostly shell options), see help set.

As for printing, export called with no arguments prints all of the variables in the shell's environment. set also prints variables that are not exported. It can also export some other objects (although you should note that this is not portable), see help export.

Source Link
Chris Down
  • 126.9k
  • 26
  • 272
  • 267

export exports to children of the current process, by default they are not exported. For example:

$ foo=bar
$ echo "$foo"
bar
$ bash -c 'echo "$foo"'

$ export foo
$ bash -c 'echo "$foo"'
bar

set, on the other hand, sets shell attributes, for example, the positional parameters.

$ set foo=baz
$ echo "$1"
foo=baz

Note that baz is not assigned to foo, it simply becomes a literal positional parameter. There are many other things set can do (mostly shell options), see help set.

As for printing, export called with no arguments prints all of the variables in the shell's environment. set also prints variables that are not exported. It can also export some other objects (although you should note that this is not portable), see help export.