views:

80

answers:

3

Hi all,

I'm new to bash shell scripting, and have come across a challenge. I know I can reload my ".profile" file by just doing:

. .profile

but I'm trying to the same in a bash script I'm writing and it is just not working. Any ideas? Anything else I can provide to clarify?

Thanks

A: 

The bash script runs in a separate subshell. In order to make this work you will need to source this other script as well.

Ignacio Vazquez-Abrams
I'm not sure (still new to all of this) what you exactly mean by "source"-ing the other script. Could please expand a little on that.However I have tried:$ . ~/.profile$ . /etc/profilewith no success. Thank you so much.
amirrustam
@amirrustan: Your script will need to source your `.profile` file something like this: `. $HOME/.profile` and you will need to start your script by sourcing it also. Something like `. /path/to/yourscript`
Dennis Williamson
@amirrustam please read http://superuser.com/questions/176783/what-is-the-difference-between-executing-a-bash-script-and-sourcing-a-bash-script/176788#176788
lesmana
A: 

Try:

#!/bin/bash
# .... some previous code ...
# help set exec | less
set -- 1 2 3 4 5  # fake command line arguments
exec bash --login -c '
echo $0
echo $@
echo my script continues here
' arg0 "$@"
tilo
A: 

To get more clarity about source (ing) and other stuffs, read this 4 Ways of Executing a Shell Script in UNIX / Linux

thegeek