|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
hi,
I would like to know how I can execute a shell script without having to sorce it? Im on Unix solaris. rite now i do . ./myscript.sh shouldnt it be just ./myscript.sh .please explain and help. is .sh necessary?... thanks in advance. |
|
#2
|
||||
|
||||
|
You run a script like this:
./myscript.sh Just make sure you have execute permissions on it. >> is .sh necessary?... No, you can rename your file to anything you want (myscript, myscript.foo, myscript.bat etc.).
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
|||
|
|||
|
As well as the correct permissions make sure that you
have something like the following as the first line of the script so that the correct shell interpreter is used to execute the script. #!/usr/bin/ksh for the Korn shell, #!/usr/bin/sh for the POSIX shell, and so on. |
|
#4
|
||||
|
||||
|
In addition to the above comments, if you place the script in your PATH you can just execute the file without being calling it with it's full path-name.
For example I have a lot of scripts I use on a regular basis in ~/bin (in fact many of these are actually symlinks to other scripts, but that's another story:P). In my ~/.cshrc I make sure I have '~/bin' in my PATH env variable: set path = ($HOME/bin ... other/paths (note this is different for bash/ksh/etc). This way when I want to execute a script that resides in ~/bin I can do so from any directory just as: myscript.sh (without the leading path to the script). HTH.
__________________
FreeBSD Admin Tips Tricks and Scripts |
|
#5
|
||||
|
||||
|
Quote:
Erm, I think you mean /bin/ksh and /bin/sh, not /usr/bin/ksh and /usr/bin/sh. On most BSD and Linux systems (RedHat, NetBSD, OpenBSD and FreeBSD), your default shells are usually in /bin, not /usr/bin. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > how to execute shell script? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|