The difference between #. / And # .. /

What is the difference between running a script like

# ./test 

and

 # . ./test 

the test is a simple script for example

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

I know the results, but not sure what is actually happening

thanks

+4
source share
3 answers

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

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

In your code example, you need to use the second method if you want the exported variables to be available in your shell.

+7
source

When using only one point, bash is the "source" of the specified file. It is equivalent to the built-in source and tries to include and execute the script within the same shell process.

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

+2
source

The first means that the script (or binary) will be executable. Using a script (possibly) containing a shebang string indicating which interpreter to use.

The second short command is for "execute [argument] as a shell script". A file passed as an argument does not need an executable bit.

0
source

Source: https://habr.com/ru/post/1393155/


All Articles