Create $HOME/bin symlink pointing to remote directory that works with $HOME/bin specified in $PATH

667 Views Asked by At

I've made a folder under my home directory called profiles. I've moved my dot profiles to this folder, and then symlinked to them in the home folder with command like ln -s ~/profiles/.bashrc ~/.bashrc.

Likewise, I created the following symlink for my user-specific bin folder in my $HOME directory, ln -s ~/profiles/bin ~/bin.

My PATH includes ~/bin (i.e. actually /home/<me>/bin), which after the steps above is actually a symlink to the ~/profiles/bin folder.

However, why does the shell not find the scripts I place in ~/profiles/bin that have executable permissions when I don't use a relative or absolute path on the command line? Such as for an ack script I've downloaded into the bin folder,

$ ack hello *.txt

EXTRA INFO: You may ask why I'm doing this. Well, I'd like to create a Mercurial repo in the ~/profiles/ folder that has all my configs and customizations for linux, but I want that to be separate from a repo I create directly in the $HOME folder that will capture my user files, such as my edits to documents, etc., that are in multiple subfolders directly under $HOME.

The thought is that I want to be able to easily pull/transfer modifications made in my profiles to different linux machines, without bringing my data files to every machine where I bring the profile customizations. And yet, I would still like to create a repo directly in $HOME folder for each machine (while ignoring the profiles folder and bin folder) to capture my user data.

So to give an example, if I have machine A & machine B, I would have 3 repos:

  • repo1 is essentially my 'profile' repo and would capture everything in my $HOME/profile folder,
  • while repo2 would capture everything else residing in $HOME on MachineA,
  • and repo3 would capture everything else residing in $HOME on MachineB.
  • The desire is not to clone the user data between MachineA & Machine B b/c the data doesn't belong on the opposite machines (they are built to serve different purposes).
  • additionally, the symlinks like .bashrc would be commited in repos 2&3 and be static, so they wouldn't change when I update the actual profiles or add new scripts in ~/profiles/bin. I could easily track changes independently in my profiles and data, potentially reverting back in time on either repo without affecting the other repo.

I would then be able to easily pull and keep in sync my profile customizations to either machine via repo1, including any custom scripts I've written/downloaded to augment the shell with commands in ~/profiles/bin (like ack). Then I could actually execute the custom commands as-if it was part of the OS since the ~/bin in the $PATH is actually a symlink pointing to ~/profiles/bin, and not having to tack on another path inside the ENV $PATH.

I'm not saying that this is the best way to structure things (and there's some more details I don't wish to elaborate and make this thread longer). I do understand that I COULD easily add "~/profiles/bin" directly to the $PATH, or push my data under something like a master '$HOME/docs' folder so the profile repo could be directly under $HOME and repo2 could exist separately in the 'docs' folder, but I'm more curious why the shell doesn't follow the symlink when scanning for executables referenced in the $PATH variable in the way I currently have it set up.


(Response to questions) Rather than screenshot (for security of certain details (work environment)), I copy the following output from terminal. I am trying to run perldoc perllocal to see what perl modules are installed on a system where admin hasn't installed the perl-doc package. I can run the program as ~/bin/perldoc perllocal or ~/profiles/bin/perldoc perllocal but not natively from any location or even directly in the bin directory (1st location in my path) because it doesn't recognize the 'bin' symlink redirection and falls back to the 3rd entry (/usr/bin) before it executes perldoc.

> rthils@MachineA:~/bin $ pwd -P
> /home/rthils/profiles/bin
> rthils@MachineA:~/bin $ ll
> total 4
> -rwxr-x--- 1 rthils rthils 275 Jul 29 23:19 perldoc
> rthils@MachineA:~/bin $ echo $PATH
> /home/rthils/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
> rthils@MachineA:~/bin $ cd ..
> /home/rthils
> rthils@MachineA:~ $ 
> rthils@MachineA:~ $ ll
> total 36
> lrwxrwxrwx 1 rthils rthils    14 Jul 29 23:34 bin -> ./profiles/bin
> drwxr-x--- 4 rthils rthils  4096 Jul 29 23:35 profiles
> rthils@MachineA:~ $ perldoc
> You need to install the perl-doc package to use this program.
> rthils@MachineA:~ $ type perldoc
> perldoc is hashed (/usr/bin/perldoc)
> rthils@MachineA:~ $ cat /usr/bin/perldoc
> #!/bin/sh
> # place-holder, diverted by perl-doc
> echo You need to install the perl-doc package to use this program. >&2
> exit 1
> rthils@MachineA:~ $ cd bin
> rthils@MachineA:~/bin $ ll
> total 4
> -rwxr-x--- 1 rthils rthils 275 Jul 29 23:19 perldoc
> rthils@MachineA:~/bin $ perldoc
> You need to install the perl-doc package to use this program.
> rthils@MachineA:~/bin $ cd ~/profiles/bin
> rthils@MachineA:~/profiles/bin $ ll
> total 4
> -rwxr-x--- 1 rthils rthils 275 Jul 29 23:19 perldoc
> rthils@MachineA:~/profiles/bin $ perldoc
> You need to install the perl-doc package to use this program.
> rthils@MachineA:~/profiles/bin $ ./perldoc

The last line spits out the help syntax from the /usr/bin/perldoc file I copied from a different system, and when ran with ./perldoc perllocal displays the perl modules.

I didn't specify bash vs shell b/c I have some environments where I must use ksh, so didn't want to only find working solution, but .bashrc was a simple example for making point what I'm attempting to do by separating and linking to my profiles.

0

There are 0 best solutions below