The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell Scripts kwliew999 AIX 7 06-12-2007 05:06 PM
Using #! /bin/sh in Shell scripts sumesh.abraham Shell Programming and Scripting 4 12-01-2006 02:29 AM
Help With Shell Scripts ragha81 Shell Programming and Scripting 6 08-18-2006 05:57 PM
Need Help With Shell scripts holler1 Shell Programming and Scripting 2 07-30-2006 11:43 PM
Difference between writing Unix Shell script and AIX Shell Scripts haroonec AIX 0 04-11-2006 11:27 PM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-16-2001
ober5861's Avatar
Registered User
 

Join Date: Jul 2001
Location: Gettysburg, PA
Posts: 116
Question where to put shell scripts?

This could be a really dumb question, but for a newbie trying to learn, some help would be appreciated. When you write a shell script, what extension should it have, and more importantly, where do you put it????
Forum Sponsor
  #2 (permalink)  
Old 07-16-2001
Registered User
 

Join Date: Jun 2001
Posts: 41
Shell scripts can have any extension that you want. I usually use .sh extension, but it's not a rule. The only things you must consider are:
- remember to put #/bin/"shell" in the beginning of your scripts
- give appropriate execution permission to the script.
I recomend you to create a standard for your shell scripts, like I did putting .sh as an extension for the scripts. About the place where you put them, you decide, but remember always to create a stantard for you, it can save you in critical hours.

HTT
  #3 (permalink)  
Old 07-16-2001
Registered User
 

Join Date: Jul 2001
Location: California
Posts: 42
Lightbulb

should be #!/bin/whateverSell
(i.e.#!/bin/sh )

My personal opion

if this shell is for admin. purpose, I put it
on /usr/bin, /usr/sbin or something defined on
path. To check it, type "echo $PATH" or "env"

if the shell is for personal use, I put it on
my home dir.

__________________
:rolleyes:
  #4 (permalink)  
Old 07-16-2001
Registered User
 

Join Date: Apr 2001
Posts: 25
As far as where to put the script....
Anywhere you like as long as the directory where the script resides is on the path

echo $PATH
to view the search path for executables.

To add your directory to the path
PATH=$PATH;your_dir
(this is typically done in your .profile or ENV file (.kshrc or whatever)

Assuming you're running korn shell
  #5 (permalink)  
Old 07-16-2001
Neo's Avatar
Neo Neo is offline
Administrator
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 4,191
Remember that some day you might need to complete upgrade your OS and OS distribution.

In that case you are better off to keep the original source distribution clean and to put all your own stuff in:

/usr/local/bin

or

/usr/local/sbin


It is also a good idea to create a distinct disk partition for /usr/local or to go as far as to have an entire /usr/local hard disk (that is what I do):

/usr/local/bin

/usr/local/sbin

/usr/local/apache/bin

/usr/local/mysql/bin

/usr/local/src ..........


When you keep the applications and custom stuff out of the way of the standard OS stuff, it makes your life much easier when you have to upgrade; move to bigger disks; insall a new OS, etc.
  #6 (permalink)  
Old 07-16-2001
Registered User
 

Join Date: Nov 2000
Location: India
Posts: 83
Hi

Regarding a shell script's extension, it can have any extension and it's location depends on how do you want to use it. For e.g if you are starting with writing scripts then you can make a script (not specific can be of any name) in your home directory and then run it from there. Also ther are some scripts which bring up the database or the javawebserver. now since in some organisations these tasks needs to be automated, system admins usually place these scripts where the other system startup or runlevel scripts are placed.
Basically you need to place your scripts depending on how you are using them or what they are supposed to do or what login specific variables do they use.
Hope this helps
  #7 (permalink)  
Old 07-17-2001
mod mod is offline
Registered User
 

Join Date: Jul 2001
Location: Vienna
Posts: 29
Like all the others told you there is now restriction from the system on how to name shell-skripts or where to put them ...
but there are two things which are worth to think about it:

1. name the script with the same extension like the shell is .. eg:
#!/bin/sh .... skript.sh
#!/bin/csh ... skript.csh
#!/bin/ksh ... skript.ksh

I saw in the last years that its easier to do it like this ...

2. skripts which points to an application could be stored in the application tree or in the home-dir of the application-user
skripts for the system-administration /usr/local/sbin
skripts for users or any other purpose in /usr/local/bin

thats the way we were happy with in the last years ...
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:34 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0