Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between #./ and #. ./

whats the difference between executing script like

# ./test

and

# . ./test 

test is simple script for example

#!/bin/bash
export OWNER_NAME="ANGEL 12"
export ALIAS="angelique"

i know the results but im unsure what actually happens

Thanks

like image 520
user1127747 Avatar asked Jan 17 '23 16:01

user1127747


2 Answers

./foo executed foo if it's marked as executable and has a proper shebang line (or is an ELF binary). It will be executed in a new process.

. ./foo or . foo loads the script in the current shell. It is equal to source foo

With your example code you need to use the second way if you want the exported variables to be available in your shell.

like image 54
ThiefMaster Avatar answered Jan 20 '23 05:01

ThiefMaster


With the dot alone, bash is "sourcing" the specified file. It is equivalent to the source builtin and attempts to include and execute the script within the same shell process.

The ./ starts a new process, and the current shell process waits for it to terminate.

like image 23
Blagovest Buyukliev Avatar answered Jan 20 '23 05:01

Blagovest Buyukliev