home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] am i just misunderstanding how the "source" command works?

  • Subject: Re: [OCLUG-Tech] am i just misunderstanding how the "source" command works?
  • From: Richard Guy Briggs <rgb [ at ] tricolour [ dot ] net>
  • Date: Sat, 15 Mar 2014 09:24:53 -0400
On 14/03/15, Robert P. J. Day wrote:
> 
>   currently playing with fedora (pre-21) rawhide, went to start
> mariadb server:
> 
>   # systemctl start mariadb-server
> 
> and got (from output of "journalctl"):
> 
> mariadb-check-socket[3942]: /usr/libexec/mariadb-check-socket: line 8: ./mariadb-scripts-common: No such file or directory
> systemd[1]: mariadb.service: control process exited, code=exited status=1
> systemd[1]: Failed to start MariaDB database server.
> 
>   so i checked the script /usr/libexec/mariadb-check-socket and, sure
> enough, line 8:
> 
>   source ./mariadb-scripts-common

What was the working directory of that script?

> but i'm fairly sure the "source" command uses the PATH variable to
> find scripts to source,

Not if it is prefixed by "./".  That will anchor that script in the pwd
of the running script (which could change during its execution).

> and there's no guarantee the above would work,
> even when that "common" script to be sourced is in the same directory
> as the sourcing script, isn't that correct?

So say that script is in the same directory as the calling script and in
the calling script, a "cd <mumble>" command is executed?

>   as a hacky test, i edited the sourcing script and changed that line
> to:
> 
>   source /usr/libexec/mariadb-scripts-common

I would use instead a local variable in the script that records the
starting working directory of that script and then prepend that variable
to that script name.

> at which point that source operation worked, as i expected it would.
> 
>   the above strikes me as simply a bug ... am i missing something here
> that would allow the original sourcing script to work properly? i'm
> about ready to file a bug report.

I would certainly say it is a bug one way or another.

> rday

	slainte mhath, RGB

--
Richard Guy Briggs               --  ~\    -- ~\            <hpv.tricolour.net>
<www.TriColour.net>                --  \___   o \@       @       Ride yer bike!
Ottawa, ON, CANADA                  --  Lo_>__M__\\/\%__\\/\%
Vote! -- <greenparty.ca>_____GTVS6#790__(*)__(*)________(*)(*)_________________