The dot (.) or source command is used to evaluate shell scripts in the current execution context
Questions tagged [dot-source]
35 questions
318
votes
8 answers
In PowerShell, how do I define a function in a file and call it from the PowerShell commandline?
I have a .ps1 file in which I want to define custom functions.
Imagine the file is called MyFunctions.ps1, and the content is as follows:
Write-Host "Installing functions"
function A1
{
Write-Host "A1 is running!"
}
Write-Host "Done"
To run…

willem
- 25,977
- 22
- 75
- 115
107
votes
2 answers
Using dot or "source" while calling another script - what is the difference?
Let's take a little example:
$ cat source.sh
#!/bin/bash
echo "I'm file source-1"
. source-2.sh
And:
$ cat source-2.sh
#!/bin/bash
echo "I'm file source-2"
Now run:
$ ./source.sh
I'm file source-1
I'm file source-2
If I'll change the call of the…

setevoy
- 4,374
- 11
- 50
- 87
89
votes
2 answers
Replacement for source in sh
I need to set the environment variables, usually we do this by
source script.sh
But now, I am automating it during the boot process and it looks like the root boots by default with sh shell. How do I source this script in sh?

vkris
- 2,095
- 7
- 22
- 30
25
votes
4 answers
Run bash script as source without source command
Is there any way to mark a script to be "run as source" so you don't have to add the source or "." command to it every time? i.e., if I write a script called "sup", I'd like to call it as
sup Argument
rather than
source sup Argument
or
. sup…

typeoneerror
- 55,990
- 32
- 132
- 223
24
votes
1 answer
"source" command in shell script not working
I have a file to be sourced in Centos 7.
It just works fine if I do :
$ source set_puregev_env
however, if I put this in a shell script, it doesn't work..
$ sh xRUN
xRUN: line 3: source: set_puregev_env: file not found
this is my shell script :…

RETELLIGENCE
- 251
- 1
- 2
- 3
12
votes
1 answer
What's the difference between: ". [script]" or "source [script]", "bash [script] or $SHELL [script]", and "./ [script]" or "[script]"?
I know that source and . do the same thing, and I would be surprised to learn if the other pairs of commands in the title don't so the same thing (because I'm running bash as my shell, $SHELL [script] and bash [script] are equivalent, right??).
So…

Ari Sweedler
- 807
- 7
- 25
9
votes
2 answers
`source ~/.bash_profile` do not works inside a bash script
This is a script that move a bash file into homepage and load it with source command.
# update.sh
#!/bin/bash
cp -f $PWD/bash_profile ~/.bash_profile
source ~/.bash_profile
It does not work! It update file with cp -f $PWD/bash_profile…

sensorario
- 20,262
- 30
- 97
- 159
4
votes
3 answers
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

user1127747
- 55
- 3
3
votes
1 answer
How does PSScriptRoot inside Dot-Sourced file work?
Suppose I have 2 files, A.ps1 and B.ps1, in this directory structure:
-- root
|
|-- A.ps1
|
|-- subfolder
|
|-- B.ps1
A.ps1:
Write-Host $PSScriptRoot
B.ps1:
. "\root\A.ps1"
Now, taking this fact into account:
Dot sourcing takes the…

Prid
- 1,272
- 16
- 20
3
votes
2 answers
Dot sourcing a PowerShell script not ending with .ps1
From a PowerShell program, I can "dot source" another PowerShell program. i.e I can execute it as if it were written inside the first one.
Example:
Write-Host 'before'
. MyOtherProgram.ps1
Write-Host 'after'
MyOtherProgram in 'included' inside…

Gregory MOUSSAT
- 832
- 4
- 13
- 22
2
votes
2 answers
Why PowerShell.exe There is no way to dot source a script?
The help document says that the script will be executed in 'dot-sourced' mode, but it doesn't. why?
I read the full text of the help document and couldn't find the reason, so I came for help.
PS> PowerShell.exe -File '.\dot-source-test.ps1'
PS>…

Andy
- 1,077
- 1
- 8
- 20
2
votes
1 answer
Permanently dot Source a File?
I am using a Custom-Powershell-Script all the time. I simply can Dot-Source the File, but I have to do this in every session.
. .\Hello-World.ps1
Is there a way to dot-source a file permanently? I don't want to do this over and over again.

Peter Core
- 193
- 1
- 2
- 16
1
vote
2 answers
Source my .zshrc in a bash script
Lets say I have this bash script (test):
#!/usr/bin/env bash
source ~/.zshrc
In my .zshrc, I have the following:
autoload -U compinit
compinit
When I try and run 'bash test' from my terminal window (zsh), I get errors saying autoload and compinit…

kelsmj
- 1,183
- 11
- 18
1
vote
1 answer
how to dot the relative path with arguments in powershell script
I have a header.ps1 file that need to be called from the Main.ps1 script. They are both under the same directory.
In the header.ps1 file, it started off with following...
[CmdletBinding()]
param(
[String]$PROJECTNAME = …

Liang Cui
- 131
- 1
- 14
1
vote
0 answers
PowerShell report what functions are loaded from a script
I have a number of scripts downloaded from the internet, and they only contain function definitions, i.e. not constructed as Modules. Hence, if I run these scripts, there is no output. If I dotsource these scripts, there is still no output, but the…

YorSubs
- 3,194
- 7
- 37
- 60