0

Can you guys tell me how to write a shell script which declares for example a variable in the shell like this: var="foobar". It just has to write the exact same thing like I would write it manually in the shell.

appreciate help because this would help me a lot ! I am not so experienced in shell scripting :/

1 Answer 1

2

For this, you have to create a script (file.sh, for example) containing the line:

var="foobar"

and then source the file:

source file.sh

or

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

1 Comment

Just want to add that there is NO way to influence the parent shell if it calls a script as a new process (i. e. just by ./script.sh or similar). To enable a script to influence its caller one must use source (abbreviated as .) or do other stuff like eval the output of a called script: eval "$(./script.sh)".

Your Answer

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