The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
making a archive script jimmyc Shell Programming and Scripting 1 09-15-2007 05:02 AM
making script shary Shell Programming and Scripting 2 06-03-2007 05:16 PM
Need help making a script npereira Shell Programming and Scripting 2 01-06-2007 01:14 PM
Making flags for my script rcunn87 Shell Programming and Scripting 6 06-29-2006 11:23 AM
Help with making a parameter check script. GCTEII Shell Programming and Scripting 2 03-07-2006 03:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-06-2005
BuyoCat BuyoCat is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 3
Making a script exectuable

Hi, I'm pretty new to Unix and I just have a question concerning making a script executable without putting the "sh" command before it. In case it makes the difference I am on an Apple computer using the Terminal. Anyway here is the little test code I wrote followed by the commands I took to try to make it executable on its own.

Script
#! /bin/sh
# comments
echo "blah"

heh that's it, it works when I do enter sh Script
now then the code I tried to use to execute it

chmod u+x Script
pwd ; echo $PATH

and though no errors came up, it didn't work. So any insight would be really appreciated. Thanks.
  #2 (permalink)  
Old 09-06-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
chmod u+x Script
just makes the script executable. It does not execute it.

pwd ; echo $PATH
this displays the current working directory and then it displays the value of PATH

To run the script try:
./Script
  #3 (permalink)  
Old 09-06-2005
BuyoCat BuyoCat is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 3
well perhaps I'm just confused and expecting a greater return than possible. I expected after running the chmod I would be able to run the script (by typing the script name or ./script) from anyplace as I would other commands such as ls or mv, however at the moment all I can do is run the script through placing it, ie ./folder/folder/folder/script, which seems terribly inconvenient, maybe you can help just by clearing this confusion up for me.
  #4 (permalink)  
Old 09-07-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,131
./Script is a path to the script. To run the script without specifying a path, you need to put Script in one of the directories in your PATH environment variable. Typically you would add some directory of your own to your PATH. This is basic stuff and you should read a unix tutorial. Go to our FAQ section and look at the tutorial thread. There are links to a lot of titorials there.
  #5 (permalink)  
Old 09-07-2005
Sabari Nath S Sabari Nath S is offline
Registered User
  
 

Join Date: Jul 2005
Location: Chennai
Posts: 46
Hi,

Your question is not that clear ... Can u make it more elaborate ...

Anyway I am writing this based on whatever I cud understand from the qn.

chmod just sets the permissions for a file or directory .... If we need to execute the script, we have to do it explicitly ... either as "sh scriptname" or just "scriptname" ... and the absolute or relative path too if u r not running the script from the directory where the script is kept ....

If your concern is that you have a script somewhere and u want to execute it from any other directory without taking the pain of giving the entire path and running each time ... can try this ....

Edit your .profile file in your home directory ... and put an alias for this script ..

runfromanywhere=/dir1/dir2/dir3/scriptname

now u can just give runfromanywhere and execute ur script from anywhere ... hope i answered ur qn ..
  #6 (permalink)  
Old 09-07-2005
amitverma amitverma is offline
Registered User
  
 

Join Date: Sep 2005
Posts: 15
just copy the file in the /usr/bin directory and make it executable...
but u'll need root's login for that...
and be careful not to disturb other files in that directory
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0