When you run "./script.sh", you are telling the shell to execute the script as a separate process. The shell creates a new process to run the script, and any changes made to the environment (such as setting environment variables) by the script are only visible within that new process. The script is executed in a sub-shell and any changes made in the script to the environment variables, current working directory, etc. will not affect the parent shell that executed the script.
On the other hand, when you run "source script.sh", the script is executed within the current shell process, and any changes made to the environment by the script affect the current shell. The script is executed as if its commands were typed directly into the shell. This means that any changes made to environment variables, current working directory, etc. by the script will affect the parent shell that executed the "source" command.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-04-04 23:23:15 +0000
Seen: 16 times
Last updated: Apr 04
How can I print all but the first 1000 Lines from a File in Bash?
Bash Script that checks if a Host is available or not?
How can I check the expiry of a SSL certificate in the Command Line?
How can I only get the Column with the Filename from a ls -all output with Awk?
How can I fix error: Security violation, ping RPC from uid 1001 in Slurm log?
I want to grep for "```*" in a File, in other Words: "```" followed by any Word
Sed: I want to remove a Word after all ``` in the given File
Bash: How can I move all files containing a certain pattern to a different directory?