Results 1 to 6 of 6
Dear Friends,
I just want to know that how can I execute my scripts (example.sh) files like other normal commands from command-line. Please describe the full method.
thanks in advance...
- 06-23-2010 #1Just Joined!
- Join Date
- Jun 2010
- Posts
- 3
How to execute example.sh files like other commands?
Dear Friends,
I just want to know that how can I execute my scripts (example.sh) files like other normal commands from command-line. Please describe the full method.
thanks in advance
- 06-23-2010 #2Just Joined!
- Join Date
- May 2010
- Location
- uk
- Posts
- 20
I don't know how to do it entirely yet, but I know if you add the directory where they are to the PATH variable using "export PATH="$PATH:directory" and change it to be executable using chmod u+x script.sh.
But then it only lasts till you close it the shell (the path thing, not the chmod thing)
Kay, figured it out (uh... looked it up) you put it in the ~/.bashrc file:
PATH=$PATH:directory
Then when you type yourscript.sh it works just like any other command.
- 06-23-2010 #3Linux.com :: Setting up a home directorya directory for personal binaries
A directory for binaries is simply a directory where you store executable files. To make the shell recognize it, add this directory to your path variable, as defined in your ~/.bashrc file. The directory can have any name. I prefer sticking with the bin convention and putting it right in the home directory: ~/bin.
To make your own bin directory and add it to your path, do the following:
1. Use mkdir to make a bin directory in your home directory:
$ mkdir ~/bin
2. Use a text editor to edit your .bashrc, and change the path to include ~/bin. It is a quoted, comma-delimited list. For example:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:~/bin:."
In your own bin, you can put scripts and tools of your own devising. They will be executable by you, but by no other users on the system. To make a file executable by all users, the superuser will have to put the file in /usr/local/bin, the system-wide local directory for binaries.
NOTES: The current shell won't recognize any changes you make in your .bashrc; you'll have to run it by hand the first time, or just exit and start a new shell.
In fact, some Linux distributions have already set this up for you.
Create the bin directory, and you are all set. at boot time
the system will recognize your bin directory, and it will be automatically
added to your path.
Remember to make your scripts executable.
And try to avoid naming them with the same name asCode:chmod +x foo.sh
critical system commands.LOL
- 06-24-2010 #4Just Joined!
- Join Date
- Jun 2010
- Location
- Mumbai
- Posts
- 5
Hi
To run a script as any other unix/linux command, make sure the first line in the script is calling a shell in which the script will run. Like "#!/bin/bash" etc.
Give permissions to owner, group and others who will have right to run the script.
chmod o+x example.sh (refer to chmod and chown commands man page)
from your login prompt sun the command
$ ./example.sh (or give path name of the file)
If you want to run the command (script) without specifying the path, add location of the script to PATH environment variable.
- 06-24-2010 #5Just Joined!
- Join Date
- Jun 2010
- Posts
- 3
thanks rcgreen
is it a secure method?
actually I am a new user that's why ..!
thanks for ur answer
- 06-24-2010 #6Just Joined!
- Join Date
- Jun 2010
- Posts
- 3
thanks for all your answers, everyone give me a new idea.
thanks again


Reply With Quote