2

My script use and modifies a shell variable. I need to always use:

source myscript

Is there a shorter way to call this script and have it modify the current shell's environment?

It can be elegantly done by using functions use as described in this answer, but I need a faster way.

  • Do you mean faster as in - faster execution (performance), or faster setup (not having to modify .bashrc)? I ask because it never occurred to me wrapping it in a function would imply a performance deficit (if this is indeed the case). I suppose I could test this with time? – Emanuel Berg Sep 16 '12 at 21:51
5

You can use . as a shorthand for source. From the bash(1) man page:

.  filename [arguments]
source filename [arguments]

Read and execute commands from filename in the current shell environment and return
the exit status of the last command executed from filename.
  • Note that . is the POSIX standard name for this command (source is a bash-specific synonym). – chepner Sep 22 '12 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.