 |
 |
 |
 |
| Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum. |

5th July 2006, 11:10 PM
|
|
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.
|

5th July 2006, 11:11 PM
|
 |
Retired Community Manager & Avid Drinker Of Suds
|
|
Join Date: Feb 2005
Location: Rochester NY
Age: 38
Posts: 4,176

|
|
|
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?
|

5th July 2006, 11:54 PM
|
 |
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
|

6th July 2006, 12:47 PM
|
|
Registered User
|
|
Join Date: Oct 2005
Posts: 1,952

|
|
|
Mat so when does it force you to use the ./filename syntax?
|

6th July 2006, 01:08 PM
|
 |
Registered User
|
|
Join Date: Oct 2005
Location: Switzerland
Age: 30
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)
|

6th July 2006, 02:59 PM
|
|
Registered User
|
|
Join Date: Oct 2005
Posts: 1,952

|
|
|
oh. that makes sense
|

6th July 2006, 06:07 PM
|
|
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
|

16th July 2006, 04:49 PM
|
|
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.
|

16th July 2006, 06:26 PM
|
|
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
|

16th July 2006, 08:47 PM
|
|
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.
|

16th July 2006, 09:06 PM
|
|
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.
|

17th July 2006, 09:51 AM
|
 |
Registered User
|
|
Join Date: Oct 2005
Location: Switzerland
Age: 30
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.....
|

17th July 2006, 06:58 PM
|
|
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.
|

18th July 2006, 09:00 PM
|
|
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...
|

18th July 2006, 10:43 PM
|
|
Guest
|
|
Posts: n/a

|
|
|
You wrote $answer where it should have been $1.
A common typo! ;-)
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 19:58 (Friday, 24-05-2013)
|
|
 |
 |
 |
 |
|
|