Fedora Linux Support Community & Resources Center
  #1  
Old 5th July 2006, 11:10 PM
Jongi Offline
Registered User
 
Join Date: Oct 2005
Posts: 1,952
Creating executable files

So if I create an executable file with the 1st line as:

#!/bin/sh

Does it mean that if I have it with an .sh extenion it will need me to run it with ./filename or sh filename?

And without the .sh extension I can just type filename (assuming it is in the path or current directory)?

All the above assumes the command: chmod +x filename has been run.
Reply With Quote
  #2  
Old 5th July 2006, 11:11 PM
jim Offline
Retired Community Manager & Avid Drinker Of Suds
 
Join Date: Feb 2005
Location: Rochester NY
Age: 39
Posts: 4,175
yes the above is true
__________________
Registered Linux User: #376813
Western NY
My linux site
Smolt Profile

please remember to say if you problem was solved

Did you get your id10t award today?
Reply With Quote
  #3  
Old 5th July 2006, 11:54 PM
Mat Offline
Retired Community Manager
 
Join Date: Jun 2004
Location: lair of a unix daemon
Posts: 1,155
just to clarify things..


the extension is absolutely irrelevant..

you only need to care for
1. file as to be executable (chmod +x filename)
2. the interpreter (first line of the script) has to be correct



so even if the script is just called "ban.all.Users" without any extension you can still call it...

either by calling the script with its absolute path
# /usr/local/bin/myScripts/ban.all.Users

or if you're in the directory
# cd /usr/local/bin/myScripts/
# ./ban.all.Users
(note: just calling ban.all.Users will not work, even if you're in the right directory)

or by putting the scripts' parent directory into your path and just calling the script
(regardless of the current path you're in)
# ban.all.Users


Mat
__________________
Man will always find a difficult means to perform a simple task
(Rube Goldberg)

Having fun with Tcl at
Mat's Playground
Reply With Quote
  #4  
Old 6th July 2006, 12:47 PM
Jongi Offline
Registered User
 
Join Date: Oct 2005
Posts: 1,952
Mat so when does it force you to use the ./filename syntax?
Reply With Quote
  #5  
Old 6th July 2006, 01:08 PM
liro Offline
Registered User
 
Join Date: Oct 2005
Location: Switzerland
Age: 31
Posts: 233
like mat wrotes, when your in the directory were the script resides....

cause otherwise if there would be another script with same name in your path environment the shell wouldn't know which it has to take (security reasons)
__________________
some tips and small doc's of fedora core linux setup [german] http://www.liro.ch
Reply With Quote
  #6  
Old 6th July 2006, 02:59 PM
Jongi Offline
Registered User
 
Join Date: Oct 2005
Posts: 1,952
oh. that makes sense
Reply With Quote
  #7  
Old 6th July 2006, 06:07 PM
JoeyJoJoe Offline
Registered User
 
Join Date: Apr 2006
Location: Coventry, UK
Posts: 444
I don't know about your level of experience but this page was really interesting to me (it's for the very basic beginer)

http://rute.2038bug.com/node10.html.gz
__________________
Registered Linux User #416286
Reply With Quote
  #8  
Old 16th July 2006, 04:49 PM
Jongi Offline
Registered User
 
Join Date: Oct 2005
Posts: 1,952
How would I create an executable file to mount an iso file. I want the file to execute the following:

umount /mnt/iso/
mount -t iso9660 -o loop <path to iso> /mnt/iso/

If I call the file mountiso, I would like mountiso ~/test.iso to execute the following:

umount /mnt/iso/
mount -t iso9660 -o loop ~/test.iso /mnt/iso/

So essentially I need the file to read the the arguement from the command line.
Reply With Quote
  #9  
Old 16th July 2006, 06:26 PM
JoeyJoJoe Offline
Registered User
 
Join Date: Apr 2006
Location: Coventry, UK
Posts: 444
what I would do is create the mountiso.sh in your home folder, then do in the terminal:

Code:
chmod 0755 mountiso.sh
then edit the file using something like gedit, so that it looks like:

Code:
#!/bin/sh

echo "what file would you like to mount?"
read answer
umount /mnt/iso/
mount -t iso9660 -o loop $answer /mnt/iso/
that should work for you... give it a go and try and work from there. Post back if it works
__________________
Registered Linux User #416286
Reply With Quote
  #10  
Old 16th July 2006, 08:47 PM
Jongi Offline
Registered User
 
Join Date: Oct 2005
Posts: 1,952
I thought of that. Will it be able to provide path data when I press the TAB button? If not it will be the next best alternative I suppose.

Will give it a bash shortly and report back.
Reply With Quote
  #11  
Old 16th July 2006, 09:06 PM
Jongi Offline
Registered User
 
Join Date: Oct 2005
Posts: 1,952
Yeah just tried it. As I suspected it won't allow filename completion at the prompt for the file I would like to mount, hence why I wanted it to pick up the field from the command line.
Reply With Quote
  #12  
Old 17th July 2006, 09:51 AM
liro Offline
Registered User
 
Join Date: Oct 2005
Location: Switzerland
Age: 31
Posts: 233
Quote:
Originally Posted by Jongi
Yeah just tried it. As I suspected it won't allow filename completion at the prompt for the file I would like to mount,...
to enable this, just rewrite the script from JoeyJoJoe:

Code:
#!/bin/sh

# check parameter
if [ -f $1 ]; then
  echo "no file to mount given, exit..."
  exit
fi

umount /mnt/iso/
mount -t iso9660 -o loop $1 /mnt/iso/
then, call the script with the argument of the file to mount.....
__________________
some tips and small doc's of fedora core linux setup [german] http://www.liro.ch
Reply With Quote
  #13  
Old 17th July 2006, 06:58 PM
ccrvic Offline
Registered User
 
Join Date: Apr 2006
Posts: 1,092
Quote:
Originally Posted by Jongi
so when does it force you to use the ./filename syntax?
When the executable is not in a directory mentioned in $PATH.

Vic.
Reply With Quote
  #14  
Old 18th July 2006, 09:00 PM
Jongi Offline
Registered User
 
Join Date: Oct 2005
Posts: 1,952
So I the file as:

Code:
#!/bin/sh

# check parameter
if [ -f $answer]; then
  echo "no file to mount given, exit..."
  exit
fi

umount /mnt/iso/
mount -t iso9660 -o loop $answer /mnt/iso/
but if I run # ./mountiso name.iso
Code:
no file to mount given, exit...
Reply With Quote
  #15  
Old 18th July 2006, 10:43 PM
Mariano Suárez-
Guest
 
Posts: n/a
You wrote $answer where it should have been $1.

A common typo! ;-)
Reply With Quote
Reply

Tags
creating, executable, files

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an executable/shortcut file? Voxmaris Installation, Upgrades and Live Media 5 5th October 2009 04:48 PM
makemap executable files not allowed WTF? HSHAssociates Using Fedora 9 29th July 2009 09:43 PM
Executable Jar Files Reiji Using Fedora 2 14th December 2006 03:35 PM
Running cd script files that are not executable tashirosgt Using Fedora 2 13th May 2006 01:36 PM


Current GMT-time: 12:22 (Monday, 28-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat