1

I am new to bash scripting. I came across the following piece of code and I am not able to figure it out. Please help me understand.

var1=$var1 some_function_call $var2

var2 is argument to "some_function_call" function.

I am not able to figure out exactly what is going on here. Thanks in advance.

Also any pointer to good bash scripting tutorials would be nice.

Thanks.

1

1 Answer 1

4

The environment of the new some_function_call process has "var1" set to the value of $var1; the environment variable does not change in the main interpreter. The value in $var2 is passed as an argument to some_function_call.

Sign up to request clarification or add additional context in comments.

4 Comments

there is no 'env' in the code, is 'env' implicit? Meaning is the above code snippet same as env var1=$var1 some_function_call $var2 . From what I understand by your reply, when some_function runs it has the value of 'var1' as set in this piece of code and the value of 'var1' changes only in execution scope of some_function (if var1 was '1' before this function call and var1 is assigned value '2' in this code then var1 is 2 in some_function and 1 otherwise? Please correct me if I am wrong. Thanks
@CodeWithPride: Yes, except that none of the arguments of env are supported, and there is no intermediate process between the interpreter and some_function_call.
What do you mean by "none of the arguments of env are supported". Also, I am unaware of the concept of "intermediate process" in bash. Kindly help in explanation or any links/references where I can understand these things would be very helpful. Thanks.
env has arguments it takes that changes its behavior; -i, -0, etc. If you use env then bash runs env and then env runs your program, hence env is an intermediate process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.