Linux, using 'exit' in a script

I want to use exit in a script in RHEL 6.x

Something like:

pwd
user1
exit
su - user1

Open in new window


This will restart my .profile

I know there are other ways of doing this, but I want to concentrate on how to use exit in a script

How can I do this ?

Thanks in advance
Los Angeles1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

worm-getterCommented:
usage ()
{
echo "nil arguments detected"
exit 1 #exit shell script
}

if [ $# -eq 0 ];
then
usage
fi

echo "still here!"
0
farzanjCommented:
Sorry not understanding your concerns.  Could you elaborate a little more.

You want to exit out of a user and then su - user1 just to reload your profile?

Why don't you simply reload it?

. .profile

Notice the first dot.

In bash your profile file is .bash_profile

So you need to do
. .bash_profile
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gerwin Jansen, EE MVETopic Advisor Commented:
I usually do . ~/.bash_profile - this works as long as your HOME variable is set correctly. Basically same as farzanj is suggesting.

(admin note)
If you want experts to help you, please add some explanation as to why you want to use 'exit' or experts will have to guess and make a lot of suggestions that are of no use to you. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.