Skip to content
Advertisement

Variable passed through environment not available in script

I’m trying to write an if/elif/else statement where if a variable equals “Full” it will cat a file and if the same variable equals “Quick” it will read a different, smaller file. The variable is being set outside of the script and is being exported by export var1=Quick

I have

JavaScript

When I try to run the script by calling ./test, it doesn’t seem like the variable is being set

JavaScript

Is there a reason why, even though the variable is exported outside of the script, the variable isn’t being passed to the script?

Advertisement

Answer

The following absolutely does work:

JavaScript

…where yourscript is the script in question.

As such, your question needs to be adjusted to contain enough information and details to reproduce the problem.


As an aside, your script would be better written thusly:

JavaScript

Both of the following work for me:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement