Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "./somescript.sh" and ". ./somescript.sh"

Tags:

linux

shell

Today I was following some instructions to install a software in Linux. There was a script that needs to be run first. It sets some environment variables.

The instruction told me to execute . ./setup.sh, but I made a mistake by executing ./setup.sh. So the env was not set. Finally I noticed this and proceeded.

I want to know the difference between these two methods of invoking a script. I am completely new to Linux so please be as elaborate as possible.

like image 228
zihaoyu Avatar asked Apr 14 '10 00:04

zihaoyu


1 Answers

Edit: I just realized I didn't answer the other part of your question .. but the answer by leeroy does that. I kind of answered something else, but I hope it helps :-)

The sh function runs bash on the script you present it with. See the man page for more info, but you can see sh is basically the synonym for bash

When you run a script ala ./setup.sh it identifies the script based on what is at the top of the file, normally referred to as the "Shebang"

A bash script would have

#!/bin/sh

Or similar at the top of the file, allowing you to use the dot method. You can also use other things, like a Python script can have

#!/usr/bin/env/python

And if your path is correct, it would run the script as a Python script instead of a bash one using the dot notation.

Hope that explains it in a simple manner!

like image 162
Bartek Avatar answered Sep 29 '22 07:09

Bartek