Source or Symlink or Other?

cookrdan

Dan

Posted on May 10, 2019

Source or Symlink or Other?

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.sh that will look in ~/dropbox/.bash/scripts/ and then source each script. So then each script is I believe loaded into memory(?). init.sh also 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_profile only 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?

💖 💪 🙅 🚩
cookrdan
Dan

Posted on May 10, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related