Linked Questions
43 questions linked to/from What is the difference between sourcing ('.' or 'source') and executing a file in bash?
-1
votes
1
answer
94
views
Sourcing a shell script vs. Passing it as an argument to a shell interpreter [duplicate]
I'm new in shell scripting. As I discovered today, there are at least three ways to run a shell script:
To execute it, using the absolute or a relative path:
/folder1/folder2/script.sh
./script.sh
...
0
votes
1
answer
68
views
what's the difference between bash my_script and source my_script [duplicate]
Both of two lines below seems to execute my_script. What's the difference between the two processes?
$ bash my_script
$ source my_script
0
votes
1
answer
63
views
What is the usage of "." in Unix shell scripting? [duplicate]
Please help in knowing what is the usage of . in Unix scripting.
For example:
. /apps/Infor_shar/PSSRT/PSHUP/prsm/psnp_env
0
votes
0
answers
29
views
Executing a script directly vs. executing a script via the source command [duplicate]
I saw a question recently where a user wanted to ensure that his script is only executed by using source.
My question is: what's the difference between ./test_script.sh and source test_script.sh? I ...
0
votes
0
answers
19
views
Generate zsh aliases from zsh script [duplicate]
I wrote a simple script for generating aliases in zsh shell. Here it is:
for subject in $(find $path -maxdepth 2 -type d -print)
do
dir=$(printf -- "$subject\n" | sed 's|.*/||')
alias &...
106
votes
11
answers
146k
views
Execute a specific command in a given directory without cd'ing to it?
Is there a way to execute a command in a different directory without having to cd to it? I know that I could simply cd in and cd out, but I'm just interested in the possibilities of forgoing the extra ...
35
votes
2
answers
49k
views
Source vs . why different behaviour?
I recently learned, that
. ./.a.a and ./.a.a is the same.
However trying source source .a.a gives an error. IMO, . being Bash alias for source shouldn't behave differently, so what am I missing?
...
15
votes
3
answers
10k
views
How are users able to execute a file without permission? [duplicate]
I created a Bash script which echoes "Hello World". I also created a test user, bob, using adduser.
Nobody has permission to execute that file as denoted by ls:
$ ls -l hello.sh
-rw-r--r-- 1 ...
13
votes
3
answers
20k
views
Difference between commands in bash script and commands in terminal
Are there any differences between commands that you type into the terminal and commands you include in a script?
2
votes
3
answers
4k
views
BEGIN: command not found in a bare simple awk script when run via sourcing
I'm learning awk today, but I cannot succeed in having the most simple scripts to work.
#!/usr/bin/env -S awk -f
BEGIN { }
{ }
END { }
this outputs BEGIN: command not found
or even
#!/usr/bin/env -...
2
votes
2
answers
1k
views
What method does the login shell use to read /etc/profile?
What method does the login shell use to read /etc/profile?
2
votes
2
answers
5k
views
Setting enivorment variables permanently with a .sh
Having looked at Setting up environment variables with .sh file and How to permanently set environmental variables I'm still confused as to how to properly set permanent environment variables from a ....
2
votes
1
answer
2k
views
What effect does a dot character . have in a crontab?
I have picked up a habit of including . from some blog post:
0 0 * * * . /usr/local/bin/somescript.sh
...instead of:
0 0 * * * /usr/local/bin/somescript.sh
For instance a visual cron schedule ...
1
vote
2
answers
6k
views
set environment variable from sh script in systemd service file
I am trying to use a ready-made bash script that sets env. This is the service that I'm trying to use:
[Unit]
Description=myserver service
After=multi-user.target
[Service]
Type=simple
User=ec2-user
...
3
votes
1
answer
2k
views
setting alias for sourcing a script, to run that script in jenkins with restricted permissions
I want to run source ./script_name instead of ./script_name. Can I create an alias for this ?
The Jenkins job will run the script as ./script_name and I can't edit the way it will run the script on ...