Page 1 of 1

Execute a shell script file

Posted: Wed Mar 19, 2014 1:45 pm
by Mag
Hi all!

I'm searching the best way to execute a shell script file giving the path. In a topic I read that you could just launch the file as openURL but I'm new in this topic so I'm not sure if this could be the right way.

PS
It would be very fine also whether there is the possibility to give some optional shell parameters.

Re: Execute a shell script file

Posted: Wed Mar 19, 2014 2:37 pm
by Thierry
Mag wrote: I'm searching the best way to execute a shell script file giving the path. In a topic I read that you could just launch the file as openURL but I'm new in this topic so I'm not sure if this could be the right way.
Hi Mag,
Have you checked the shell and shellCommand in the Dictionary?
This is quite well explained.

Thierry

Re: Execute a shell script file

Posted: Wed Mar 19, 2014 4:39 pm
by Mag
Hi Thierry,

thank you. Any suggestion to run a shell script located on an external file?

Re: Execute a shell script file

Posted: Wed Mar 19, 2014 5:27 pm
by Thierry
Mag wrote:Hi Thierry,
thank you.
Any suggestion to run a shell script located on an external file?
Umm, not really as I don't know what you want/need to achieve :wink:

But here is one way:

in a file, ie: /full/path/of/this/file.sh

Code: Select all

#!/bin/bash

echo "Hello LC with $1"
a simple Livecode script:

Code: Select all

put 42 into x
put shell("/full/path/of/this/file.sh  " & quote & x & quote )
And for this to work, you need to set the executable bit of file.sh

Hope this gives you a start.

Regards,

Thierry

Re: Execute a shell script file

Posted: Wed Mar 19, 2014 10:33 pm
by Mag
Hi Thierry, thank you, very useful post.

What I'm try to do is to give the user the possibility to run a shell script from within an app. I thought that the best way could be to let user to choose a file from the Finder and then run it, but an alternative could be to give the user a text field and then run the content.

I do not know the differences in results between the two methods, if any, so I would be happy to have advices and suggestions.

Re: Execute a shell script file

Posted: Thu Mar 20, 2014 7:48 am
by Thierry
Mag wrote:Hi Thierry, thank you, very useful post.
What I'm try to do is to give the user the possibility to run a shell script from within an app. I thought that the best way could be to let user to choose a file from the Finder and then run it, but an alternative could be to give the user a text field and then run the content.

I do not know the differences in results between the two methods, if any, so I would be happy to have advices and suggestions.
HI Mag,

there are not much differences for most cases,
except if:
- the size of your shell scripts are more than few MegaBytes :)
- you're calling your shell script hundred of times per second.


If you like having all your programs or files in one place, I would suggest
storing your shell script in a field, or a custom property or even in a Database.
LC is quite good for that.
If you work in team and have a shell expert; might be better to let this guy managed
a bunch of files on his own and, within LC, call them.

I would avoid typing shell scripts straight in the LC editor, otherwise
you'll have to deal with few levels of evaluation (means that you need to escape
a lot of chars in your shell script) and you'll have an ugly and hard to read piece of code.

As you said you're new to this, might be interesting for you to explore both ways?

Good luck,

Thierry

Re: Execute a shell script file

Posted: Fri Mar 21, 2014 10:50 am
by Mag
Hi Thierry, thank you so much for your help and very useful advice. Much appreciated!