0

I have a file with my Raspberry Pi address named pi. It's in my home directory.

pi=192.168.0.173

To connect to the Pi, I'd do this in my home directory:

. pi && ssh pi@$pi

It worked. Then I improved it with this script in my ~/bin:

#!/bin/bash
. ~/pi
ssh pi@$pi

Now I just do this:

pi

Of course it works. But I sometimes need the Pi IP. Then I do this in my home dir:

. pi

But instead of sourcing the file, I'm getting connected to my Pi. To make things stranger,

$ . pi && echo ok
pi@raspberrypi:~ $ logout
Connection to 192.168.0.173 closed.
ok

I get the same behaviour in all zsh, dash and sh. Could someone explain?

  • This is probably a dup, and I'll look for a more complete answer, but in the meantime: The . command follows your normal search path for executables to search for the command file, which likely doesn't (and shouldn't) include your current working directory. – Mark Plotnick Feb 16 '17 at 20:23
  • @MarkPlotnick I've edited my question to show that . pi worked before. . di still does. – Tomasz Feb 16 '17 at 20:33
  • You may have . or $HOME towards the end of your search path, after $HOME/bin. – Mark Plotnick Feb 16 '17 at 20:36
  • @MarkPlotnick That's not the case. I've checked this in a location certainly off-path. – Tomasz Feb 16 '17 at 20:39
0

man knows all of it... An excerpt from Bash's.

source filename [arguments]
      Read and execute commands from filename  in  the  current  shell
      environment  and return the exit status of the last command exe‐
      cuted from filename.  If filename  does  not  contain  a  slash,
      filenames  in  PATH  are  used  to find the directory containing
      filename.  The file searched for in PATH need not be executable.
      When  bash  is  not  in  posix  mode,  the  current directory is
      searched if no file is found in PATH.  If the sourcepath  option
      to  the  shopt  builtin  command  is turned off, the PATH is not
      searched.  If any arguments are supplied, they become the  posi‐
      tional  parameters  when  filename  is  executed.  Otherwise the
      positional parameters are unchanged.  The return status  is  the
      status  of  the  last  command exited within the script (0 if no
      commands are executed), and false if filename is  not  found  or
      cannot be read.

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.