On Fri, Jan 26, 2024 at 03:28:11PM +0200, Ricky Tigg wrote: > $ export EDITOR='/usr/bin/nano' && source $HOME/.bashrc > $ echo $EDITOR > /usr/bin/vim > > Expected: Latest command's output to be "/usr/bin/nano" instaed of > "/usr/bin/vim".
It's really unclear to me why you expected this. You're changing the variable, and then sourcing a file that changes the variable again. The last change wins. It's no different from something like this: unicorn:~$ a=5 && a=7 unicorn:~$ echo "$a" 7 You can see why the value is set to 7, right? It was set to 5, and then set to 7, and the last change is the one that sticks around. > I unexpectedly get the desired behaviour without invoking 'source'. > > $ export EDITOR='/usr/bin/nano' > $ echo $EDITOR > /usr/bin/nano This *surprises* you? Why are you surprised that the value you set it to is the value that it has? Why are you even calling "source" at all? > Hopefully, my interpretation of the 'source' command is correct. I don't think I understand what your interpretation is. What do you think 'source' does? For the record: unicorn:~$ help source source: source filename [arguments] Execute commands from a file in the current shell. Read and execute commands from FILENAME in the current shell. The entries in $PATH are used to find the directory containing FILENAME. If any ARGUMENTS are supplied, they become the positional parameters when FILENAME is executed. Exit Status: Returns the status of the last command executed in FILENAME; fails if FILENAME cannot be read.