2 ms·
Think of it like nested context in a "normal" programming language. The environment variables are state or data from the outside or encompassing context. Wherea
by zo1 10y ago
Think of it like nested context in a "normal" programming language. The environment variables are state or data from the outside or encompassing context. Whereas command-line parameters are just that, parameters passed down to a function based on some logic held within the parent context.
Within that explanation, we all know that global/shared variables are a code-smell for the most part. Say you want to call the same command with different logic, or multiple times even.
result1 = func("hello", "world");
result2 = func("hello", "another world");
vs
greeting = "hello";
greetee = "world";
result1 = func(); //How do we even know that func uses greeting and greetee variables?!
greetee = "another world";
result2= func(); //Did func change my greeting variable? I don't know.
So let's assume that greeting and greetee are actual important variables. You are essentially then sharing your "state" with the func in order to alter its behavior. I think in some shells, the functions themselves can alter global environment variables, so it would be a giant mess making sure that functions are idempotent and don't have artifacts.