Source linux not found

Getting a ‘source: not found’ error when using source in a bash script

Step 1 works quite well, but I can’t seem to activate the virtualenv. For those not familiar with virtualenv, it creates an activate file that activates the virtual environment. From the CLI, you run it using source

source $env_name/bin/activate 

Where $env_name, obviously, is the name of the dir that the virtual env is installed in.

In my script, after creating the virtual environment, I store the path to the activate script like this:

activate="`pwd`/$ENV_NAME/bin/activate" 

But when I call source «$activate» , I get this:

/home/clawlor/bin/scripts/djangoenv: 20: source: not found 

I know that $activate contains the correct path to the activate script, in fact I even test that a file is there before I call source . But source itself can’t seem to find it. I’ve also tried running all of the steps manually in the CLI, where everything works fine.

In my research I found this script, which is similar to what I want but is also doing a lot of other things that I don’t need, like storing all of the virtual environments in a ~/.virtualenv directory (or whatever is in $WORKON_HOME). But it seems to me that he is creating the path to activate , and calling source «$activate» in basically the same way I am.

Here is the script in its entirety:

#!/bin/sh PYTHON_PATH=~/bin/python-2.6.1/bin/python if [ $# = 1 ] then ENV_NAME="$1" virtualenv -p $PYTHON_PATH --no-site-packages $ENV_NAME activate="`pwd`/$ENV_NAME/bin/activate" if [ ! -f "$activate" ] then echo "ERROR: activate not found at $activate" return 1 fi source "$activate" else echo 'Usage: djangoenv ENV_NAME' fi 

DISCLAIMER: My bash script-fu is pretty weak. I’m fairly comfortable at the CLI, but there may well be some extremely stupid reason this isn’t working.

Источник

How to Resolve bin/sh: 1: source not: found

Ubuntu is a popular Linux operating system that allows you to run code using scripts. A computer error is the occurrence of a computer producing an inaccurate result. When running some scripts or doing some tasks using a terminal, you can encounter some errors that can be solved through different techniques. In this article, we will discuss the causes of the error “bin/sh: 1: source not: found” and how to resolve it.

A shell script is software that executes commands. Shell scripts are primarily used to avoid tedious tasks. Instead of entering commands one after the other n times, you can construct a script to automate a series of instructions to be run one after the other. The /bin/sh is used to run the file with sh, a Bourne shell, or another comparable shell.

Why “bin/sh: 1: source not: found” Error Occurs

While using the fypll repository, you can confront the error “bin/sh: 1: source not: found” when you start activating that using the below command:

Читайте также:  Wifi выключен механическим переключателем linux

Resolve

We can resolve the above error in multiple ways and follow the suitable way for you.

The source is not a sh built-in; it is a bash built-in, and you’re using sh rather than bash. Try using bash instead of sh.

Replace “source ./activate” with “. ./activate”

Building an automatic setup script that modifies /etc/profile and $HOME/.profile if some paths aren’t exported, then automatically reload these by the below-mentioned command:

It does not mean that the source file is not found; it means the source you are trying to access is not found, the source is a Bash built-in function, and the script isn’t run with bash

Resolve

Instead of source, “.” is supported by some shells. So, you may attempt something like the below-mentioned syntax.

Instead of using the below command:

The /bin/sh is usually a shell attempting to imitate The Shell. For “sh,” many distributions utilize /bin/bash because it supports the source. However, the source is not supported by Ubuntu which uses /bin/dash. If you cannot edit the script, try changing the shell that executes it.

Conclusion

As a programmer or computer users, we encounter certain errors daily. While using the shell, we encounter different types of errors, one of the errors is “bin/sh: 1: source not: found”. You encounter this error when running the bash script using the “sh” shell. The most common cause of this error is discussed in this article, and the possible ways to resolve this error are also discussed. You can find help from this article while resolving your error.

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.

Источник

Error message ‘source: not found’ when running a script

I am creating a little automated setup script that will modify /etc/profile and $HOME/.profile if some paths are not exported. Then, I’d like to reload these automatically. I have read that source does this, so I fired up my terminal and entered:

source /etc/profile source ~/.profile 
  1. How can I be sure that the script is executed by Bash, even if #!/bin/sh is specified (apparently, it does not guarantee it)?
  2. Why would it say that these two sources cannot be found when they are unmistakably there?

4 Answers 4

/bin/sh is not bash . To execute your script with bash , write #!/bin/bash as the first line in your script.

The error source: not found is not dropped, because /etc/profile is not found. It’s dropped, because source is not found. source is a Bash built-in function, and you don’t execute the script with bash . So it’s clear why it is not found. Change the #! line in the script, and it will work.

Читайте также:  Установка linux usb hdd

Some shells support . instead of source . So you can try something like this

This was edited to claim that csh supports . and sh supports source , but that edit was wrong and it has since been rolled back. The reverse is true: csh and tcsh support source , POSIX shells (sh) support . , and some POSIX-style shells (like bash) support both. I’m mentioning this because you had approved the edit and might otherwise wonder why it was rolled back. If you really want to say what the edit said, you can roll back the rollback—though that would make this answer wrong. (If you want this post to be more detailed, I think it would be better to do a new edit.)

this worked for me, but I had to fully qualify the path to filename, so . ./filename instead of just . filename

1. How can I be sure that the script is executed by Bash, even if #!/bin/sh is specified (apparently, it does not guarantee it)?

To be sure that a script written for sh shell (as in your case — see What is difference between #!/bin/sh and #!/bin/bash?) is executed by Bash, just run the following command:

Thus, you will not get that error anymore.

2. Why would it say that these two sources cannot be found when they are unmistakably there?

It doesn’t say that those sourced files are not there. It says that the source command is not found. This is normal, because since you start your script with #!/bin/sh line, your script will run using sh and not bash as you may think. Why is it normal? Because source command is a Bash builtin, but not a sh builtin. To source a file in sh , you should use . (dot). Example:

Another way is to change the shebang line to #!/bin/bash as chaos said in his answer.

Источник

sudo: source: command not found

I’ve been updating some of the default profile for bash, and saw from the tutorials I was following that I could reload the new profile with the new environment settings by using:

The only thing is — the new environment variables were only available to my current user — and were ignored when I used sudo. They only became available to sudo when I closed my terminal session and rejoined. When I try to use:

sudo source /etc/bash.bashrc 
sudo: source: command not found 

Is there a simple way to load in the new bash profile settings for sudo without having to close the terminal and restart? — Initially, I was using some installer scripts which referenced the variables. I found that while they could access the variables when I called the scripts directly (although, this would cause a later problem with creating directories as I needed to be root), calling the install scripts using sudo wouldn’t. I proved this by testing with these simple commands:

echo $ENV_VARIABLE sudo echo $ENV_VARIABLE 

How did you try to use the variables from sudo ? Please note that if you use «sudo command $variable» it will replace the variable from your shell, not from sudo’s environment.

Читайте также:  View all disks linux

8 Answers 8

The problem is that source is a bash build-in command (not a program — like ls or grep ). I think one approach is to login as root and then execute the source command.

sudo -s source /etc/bash.bashrc 

You’re right that the problem is that source is a shell builtin. sudo su is a kind of weird way to say it — better to just say sudo -s which is sudo’s own way of saying «start a shell as this user.» Your one-line version won’t work because each of the commands in it is run by the main user’s shell in a separate subprocess.

Right. Plus BASH reads /etc/bashrc at login time. So you may as well use ‘su’ with -, -l, or —login switch in order to get the environment of that user: ‘sudo su -‘ to become root or ‘su — $username’ to become another user.

The «one line» example won’t work because su starts a new shell and «source» is run only after it terminates. The first example only works if the second line used inside the root shell.

sudo -s has a similar effect of starting a shell, but to me it seems inelegant to stack two «become another user» commands when one would do.

The problem is not that source is a shell builtin command. The fact that it is is what’s actually throwing you the command not found error, but it doesn’t mean it would work if it were.

The actual problem is how environment variables work. And they work like this: every time a new process is started, if nothing happens, it inherits the environment of its parent. Due to this, using a subshell (e.g. typing bash inside a bash instance) and looking at the output of env should give similar results than its parent.

However, due to how sudo works (as stated in its manpage), sudo tries to strip the environment of the user and create a «default» environment for the supplanting user, so that the command run is run as if the user who invoked it had been the calling user (which is the expected behaviour), and thus running nautilus as sudo nautilus should open a folder at the /root folder, and not /home/yourusername .

Doing something like sudo source script.sh and then sudo command , even if it worked, it wouldn’t be successful at setting any variable to the later sudo command .

In order to pass environment variables, you can either tell sudo to preserve the environment (via the -E switch; and having appropriate permissions in your sudoers file) and/or setting it for the command as sudo VAR1=VALUE1 VAR2=VALUE2 command .

Источник

Оцените статью
Adblock
detector