Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run .profile inside a shell script in ubuntu

Tags:

bash

shell

sh

I am running a script which is echoing the environment variables in .profile file and than I am running the script, but I am getting following error

I tried following:

node@node-virtual-machine:~$ cat env.sh 
#!/bin/bash

echo 'export JAVA_HOME=/home/node/jdk1.6.0_45' >> /home/node/.profile
echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /home/node/.profile
cd /home/node/
source .profile
node@node-virtual-machine:~$ sh env.sh 
sudo: source: command not found

How to execute .profile within a script?

like image 730
Prats Avatar asked Oct 18 '25 07:10

Prats


1 Answers

Instead of:

sh env.sh

You should run:

bash ./env.sh

Besides instead of:

source .profile

use:

source ~/.profile
like image 98
anubhava Avatar answered Oct 19 '25 21:10

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!