0

I know that set is used to manipulate environment variables, but I want to make myself sure - these alterations are not permanent, right? I mean once I close shell and reopen it, no changes will be preserved, won't they? And they are not inherited by the child processes, lest export is used, am I correct?

I mean expressions like

set IFS ':'
7

set manipulates shell options or positional parameters. From a bash prompt type help set

The command set IFS : will set $1="IFS" and $2=":". It will not change the value of the IFS variable.

Any changes to shell options and positional parameters will not be saved between bash sessions. You have to alter your startup files (.bashrc et al) for that.

  • I typed help set and I cannot say I was able to extract the information I needed. How to change IFS with set then? – infoholic_anonymous Feb 4 '14 at 19:07
  • You don't change IFS with set, you change IFS by changing IFS like any variable: IFS="new value" – glenn jackman Feb 4 '14 at 20:39
1

set is not used to manipulate environmental variables, it is used to set shell options. Think of it as the equivalent of a Settings menu. So, while some of these options can affect the way that bash handles environmental variables, it has nothing to do with setting them.

Anyway, if you change the value of a variable like this:

foo='bar'

It will only be changed for your current shell and will not affect anything else. If you use export, like this:

export foo='bar'

It will be exported to your current shell and all shells started from your current shell but it will still not affect any shells started outside the current shell session. To illustrate:

$ foo='bar'
$ echo "$foo"
bar
$ bash   ## start a new shell
$ echo "$foo"

$

The second echo print nothing because the variable has not been exported to the new shell. If you'd used export it would have been:\

$ export foo='bar'
$ bash
$ echo "$foo"
bar

In other words, not only will variable changes like this not persist after restarting, they won't even affect any new shells you start.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.