Source or Symlink or Other?
I'm looking for some insight. I started getting into bash/terminal/etc on my mac since around January and now I use it quite a lot. I started making some small scripts to automate some things that I do and it's great!
I realized when I started that I wanted to keep scripts in a different place (cloud). I don't need to sync anything to other machines, but it's just convenient for the once in a while format that I do. So I created the following set up:
- Everything is stored in my dropbox
~/dropbox/.bash/scripts/ - I have a script called
init.shthat will look in~/dropbox/.bash/scripts/and then source each script. So then each script is I believe loaded into memory(?).init.shalso contains many other things like my prompt customization etc. - Each script contains a function - and so when I use the script I'm not using the script name, just a function name (since I source it.
- my
~/.bash_profileonly has one line:source ~/dropbox/.bash/init.sh
So for example, a script called hello.sh might be like this:
#/bin/bash
function hello () {
echo "hello world"
}
Then in my init.sh script it will do source hello.sh and I can call the hello function from terminal.
What is recommended?
I made this set up and it works, but it was when I didn't know a lot. I now know the common way to do things is by using symlinks. Is there anyone that can share some insight about why one way is better than another? Or is there another way that only code ninjas know?





First of all, welcome to the command line addicts club! I'd never thought using dropbox for that, I must say it's not a bad idea!
Although it's very common to use GitHub / Gitlab / Bitbucket (your preferred git platform here) to store your dotfiles (and shell scripts). With git you can achieve the sync problem. Now about running your scripts, I'd advice creating a bin/ directory inside your home and
symlinkingyour scripts there to call them like every other program,ln -s /route/to/your/script $HOME/bin/somecoolscript.sh.I have a .dotfiles directory on my home that I sync with github, then link files from this directory to their respective place.
I did a fast search and this article may be of help. If you have any doubts just ask!