• The Forums are now open to new registrations, adverts are also being de-tuned.

Compiling a bash script

Spinal

MB Enthusiast
Joined
Sep 14, 2004
Messages
4,806
Location
between Uxbridge and the Alps
Car
x254, G350, Duster, S320, Mach1, 900ss and a few more
Howdy, a quicky here...

I have a very short (1-line) bash script, which I want to give to my users... problem is, I'm used to invoking it from terminal and have forgotten how to compile bash scripts... if I even can from OsX... (basically I want to give them an executable application that they double click on and it runs my one-line script)

Ideas?

M.
 
If you give it suitable permissions, (e.g. chmod 755 <scriptname>), you should just be able to double click it from the Finder.
 
chmod +x /path/to/bash_script.sh

Bash is a scripting language and can not be compiled!

Could I see your one-line-script, please? :)

Cheers
Chris
 
Humm... Problem is, if I give it the "suitable" permissions, TextEdit takes over on the user accounts and opens it for them...

I've removed the extension, in an attempt to stop textEdit from recognising it, but the file is in HFS+ so it has a metadata fork... will need to remove that as well and see... Problem is, it will imply that the user needs to be able to run terminal, which my policy wont allow... grumble...

The one line script is really stupid, all it does is invoke another script, with the right parameters!

so:
Code:
#!/bin/bash
/usr/bin/sendLogon 192.168.1.1 1234 "$UserName"
exit 0
(IP and port number changed for obvious reasons...)

As for it being non-compilable, I thought there were several compilers out there for it... CCsh and aMuleCC spring to mind, neither of which I could get to work though - so that may explain a thing of two :p
M.
 
Last edited:
Spinal,

Sorry- don't get me wrong but I don't see your point. Why not to call other script with parameters? And why would you like to compile a script anyway??
Seriously, however smart and long script is - IT IS NOT A PROGRAM (hence dosn't need compiling)!

The tools which you have tried to use are only TRANSLATORS from BASH to C. You still need to review the code and compile it! (there is no need for your script).

Btw. you don't need to use bash interpreter, as this will work in any shell so /bin/sh will do.

Use .sh at the end and do chmod +x (for execute) and everything should be fine.

And more more thing- if other script will exit with error you'd like capture it so why you are doing exit 0?

It doesn't make sense to me.

Cheers
Chris
 
Code:
#!/bin/bash
/usr/bin/sendLogon 192.168.1.1 1234 "$UserName"
exit 0
(IP and port number changed for obvious reasons...)

As for it being non-compilable, I thought there were several compilers out there for it... CCsh and aMuleCC spring to mind, neither of which I could get to work though - so that may explain a thing of two :p
M.

There usually isn't much point in compiling a shell script - primarily because they are based on invoking other programs. You'd need to have the compiler embed the functionality of some programs (eg. test) to noticably improve performance.

The magic '#!' at the top with the interpreter name and execute permissions makes them appear to be self contained programs.
 
You can package up your script as an "Application" using Applescript.

Open the Applescript editor and enter the following:-
Code:
do shell script "/path/to/your/bash_script.sh"

Then do File->Save As, choose "Application" as the file format and bob's your uncle...
 
Spinal,

Sorry- don't get me wrong but I don't see your point. Why not to call other script with parameters? And why would you like to compile a script anyway??
Seriously, however smart and long script is - IT IS NOT A PROGRAM (hence dosn't need compiling)!

Because I need to be able to copy a "button" to everyone's desktop, whereby whenever they change room without logging out/in (and hence, get a new IP address without logging in again, and hence, without sending their username to the internet filter) they can just click on the "button" and resend their details...

They CANNOT run terminal, only the IT people have terminal on the software whitelist... hence, I need the script to act like a program, even though it may not be (though I disagree with your comment about a script not being a program... but lets not get into that...)

M.
 

Users who are viewing this thread

Back
Top Bottom