Path of exported variable not set as source
BASH version: 5.2.26(1)-release. OS: Fedora; Desktop edition. Hello. Current state: Vim set as default text editor. $ cat .bashrc | grep '^export EDITOR' export EDITOR='/usr/bin/vim' $ typeset -p EDITOR declare -x EDITOR="/usr/bin/vim" $ which nano /usr/bin/nano Failure: attempt to set a text editor as the default one of the current session. To reproduce in terminal $ 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". I unexpectedly get the desired behaviour without invoking 'source'. $ export EDITOR='/usr/bin/nano' $ echo $EDITOR /usr/bin/nano Hopefully, my interpretation of the 'source' command is correct.
Re: Path of exported variable not set as source
On Fri, Jan 26, 2024, 14:29 Ricky Tigg wrote: > BASH version: 5.2.26(1)-release. OS: Fedora; Desktop edition. > > Hello. > > Current state: Vim set as default text editor. > > $ cat .bashrc | grep '^export EDITOR' > export EDITOR='/usr/bin/vim' > $ typeset -p EDITOR > declare -x EDITOR="/usr/bin/vim" > $ which nano > /usr/bin/nano > > Failure: attempt to set a text editor as the default one of the current > session. > > To reproduce in terminal > > $ 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". > export var=${var:-default} to make in rc keep if set ur code says ' editor=nano source rc ' when rc is sourced , ur version sets it always , when bash reads cmds I unexpectedly get the desired behaviour without invoking 'source'. > > $ export EDITOR='/usr/bin/nano' > $ echo $EDITOR > /usr/bin/nano > > Hopefully, my interpretation of the 'source' command is correct. >
Re: Path of exported variable not set as source
On 1/26/24 8:28 AM, Ricky Tigg wrote: Hopefully, my interpretation of the 'source' command is correct. It's not: the `source' command reads and executes commands from the filename argument. What do you think it does, and why do you think the results you expected are correct? -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/ OpenPGP_signature.asc Description: OpenPGP digital signature
Re: Path of exported variable not set as source
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.