How to use source command in shell script

shshell

I would like to use source command in shell script.

What I have done is like this below:

in start.sh

source ~/tensorflow/bin/activate

then in command line run this script.

$sh start.sh

However nothing happens and

$which source

command doesn't show anything.

So, source is not the normal command?

Is this wrong idea? or how can I reduce the type of path?

Best Answer

source is a shell built-in command. The which command looks for binaries on the PATH, like in /usr/bin, /bin, /sbin, etc. but you won't find any built-in commands in a separate binary.

Also, having the source command in a shell script does not result in the source propagating up to your current shell when you run it. sh blah.sh where blah.sh has source in it will not actually source the contents of the file into your interactive shell. That's not how sourcing works.

If you want this sourcing of the tensorflow activate script to happen every time you open a new shell, you need to edit ~/.bashrc or ~/.profile(or other files, depending on what your shell is and how it's configured) and put thesource` command directly in there.

P.S. - your question title is very confusing and looks incomplete. Take some time to edit, revise and clean up your post, or you run the risk of someone downvoting it :P I'm tempted to do so myself, but I wrote an answer, so I'm a little bias...

Related Question