OSX: This works from the command line:
alias ruby="/opt/local/bin/ruby1.9"
but in side a shell script, it has no effect. I want to write a script that will switch between ruby 1.8 and ruby 1.9, so this needs to be a script – not in my profile.
It appears “source script.sh” works, but “./script.sh”. Why is this? How can I replicate this in my script?
./script.shwill be executed in a sub-shell and the changes made apply only the to sub-shell. Once the command terminates, the sub-shell goes and so do the changes.sourcing the file using
. ./script.shorsource ./script.shwill read and execute commands from the file-name argument in the current shell context, that is when a script is run usingsourceit runs within the existing shell, any variables created or modified by the script will remain available after the script completes.