1

I have set some variables in my shell, because I need them all the time. How can I make a script, that I call on the same shell that has variables set access the variables that are defined in the shell, without passing them explicitely as parameters?

1 Answer 1

1

You simply source the script with the assignments in your shell script like so:

 . /path/to/settings  # Dot, blank, name of file.

This will execute the contents of settings in the current shell (as opposed to starting a subshell, where assignments are lost after the subshell ends.)

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

2 Comments

You can also use the verbose form of the ".": "source". source /path/to/settings/ will also work.
sweet i didn't know it went this way as well

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.