Please tell me what is the difference in bash shell between launching a script with
./script.sh and . ./script.sh?
Please tell me what is the difference in bash shell between launching a script
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As klausbyskov says, the first form requries that the file have its executable permission bit set.
But more importantly, the first form executes the script in a separate process (distinct from, independent of, and unable to make changes in the shell that launched it). The second form causes the initial shell to directly run the commands from the file (as if you had typed them into the shell, or as if they were included in the script that does the ‘sourcing’).
A script that contains
FOO=bar; export FOOwill have not create an exportedFOOenvironment variable in the shell that runs the first variant, but it will create such a variable in a shell that runs the second variant.The second form (‘sourcing’) is a bit like a
#includein C.