0

I'm making myself a few "helper" scripts, and the first one is to install NodeJS. The first issue I've just solved, was getting source ~/.profile to persist changes. I found out running . /scripts/install-nodejs.sh makes this work, but without the leading ., it doesn't.

Is there anyway I can tell in the script if it was called with the period before it, so if it isn't I can output myself a message remind me how to call the script properly?

For reference, this is the script so far

#!/bin/bash

echo -n "Installing NVM..."
apt-get -qq install curl > /dev/null
curl -s https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh > /dev/null
echo "Done!"
source ~/.profile

Also, side question, is there a way to describe when a script is called with a preceding period?

3
  • 1
    I suggest against using . or source to run a script. Doing so runs the script in the context of the current shell. You don't know how that will affect the environment within the current shell -- it may have unintended consequences on future operations performed from that shell. Commented Jan 20, 2016 at 21:47
  • These scripts will be running a docker I'm using at home for a development. I understand the risks you say, but I'm my particular case, any thing that goes wrong, I can just reboot the docker container, and this would be one of the first commands run after boot. Commented Jan 20, 2016 at 21:49
  • see also unix.stackexchange.com/q/212943/117549 Commented Jan 20, 2016 at 21:59

1 Answer 1

1

The . is short hand for sourcing the script. Sourcing a script is like calling each of the commands by hand.

Check this out The Dot

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.