I am trying to understand local/environment variables and export/set commands.

$ set FILEM="razrax"
$ echo $FILEM

$ FILEN="test"
$ echo $FILEN

Please explain why echo $FILEM returns empty string


You're confusing bash with csh.

In bash like in any Bourne-like shell, set is the command to set options (shell configuration settings like -f, -C, -o noclobber...) and positional parameters ($1, $2...).

set FILEM="razrax"

Sets $1 to FILEM=razrax.

$ set FILEM="razrax"
$ echo "$1"

The syntax for variable assignment in Bourne-like shells is:


(no space allowed on either side of =).

ksh and some other Bourne-like shells (mksh, pdksh, zsh) can also assign array variables with set though:

set -A array value1 value2

zsh, bash, yash and newer versions of ksh use this syntax instead:

array=(value1 value2)

In contrast, in csh or tcsh, the syntax is:

set VAR = value
set array = (value1 value2)

(spaces around = optional).

In rc/es shells:

VAR = value
array = (value1 value2)

(spaces around = optional).

  • Thank you for nice answer. The only thing I din't understand is what the difference benweet options and local variables "set is the command to set options"? – iJava Apr 21 '15 at 11:16
  • @iJava, set -C sets the -C option (same as set -o noclobber). set foo assigns foo to $1 (and $# is 1, ($2, $3 are unset if previously set)). Check your shell's manual for details. – Stéphane Chazelas Apr 21 '15 at 11:28
  • 1
    I don't understand what ARE options. Are these options that are send to programs like main (String[] args)? Or what? Where are they used? – iJava Apr 21 '15 at 11:32
  • 1
    @iJava, they are settings that affect the shell's behaviour. Again, RTFM – Stéphane Chazelas Apr 21 '15 at 11:35

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.