Hi I am new to Linux and shell scripting.
I have made a script 'script1.sh' in a directory : /root/ansh/scripts

I want to invoke this script from any other directory . I understand that for doing this I'll have to set the path of the script in some global variable. But I have no idea as to how to go about it.
Kindly let me know.

To temporarily add a path, use the following syntax:
PATH=$PATH:/your/path/here
To add it permanantly, you need to edit the .profile file in your home directory, and add your path to the list there (which is also seperated by colons).

Thanks for the prompt response.
I am however still not clear as to how to do that .
I am working as the root user.
The name of my script is : find.sh
My shell script is in the folder "root/anshul/scripts"
Now where do I add this path, so that I may execute the script from anywhere in the unix box once I have logged in ?
Kindly elaborate on your previous reply.
Thanks.

To temporarily add a path, use the following syntax:
PATH=$PATH:/your/path/here
To add it permanantly, you need to edit the .profile file in your home directory, and add your path to the list there (which is also seperated by colons).

My shell script is in the folder "root/anshul/scripts"

OK... type this:

nano ~/.profile

Add this to the end of the line:

:/root/anshul/scripts/find.sh

Then the script will be accessible from any directory (assuming of course, that you're root).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.