Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k
Source Link
RocketNuts
  • 419
  • 1
  • 5
  • 12

Setting variables from shell: how to use them in a script?

How can I set variables to be used in scripts as well? They don't have to be global / system-wide, just the current session is sufficient. But for some reason they seem gone even if I run a script right from my current terminal.

Example:

foo=bar
echo "$foo"

output: bar

However if test.sh contains echo "$foo" and I do:

foo=bar
./test.sh

The output is empty. How do I set a scope for temporary variables with a terminal session that remains valid when executing scripts from that same session?