Execute a shell script file

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Execute a shell script file

Post by Mag » Wed Mar 19, 2014 1:45 pm

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.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Execute a shell script file

Post by Thierry » Wed Mar 19, 2014 2:37 pm

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Execute a shell script file

Post by Mag » Wed Mar 19, 2014 4:39 pm

Hi Thierry,

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

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Execute a shell script file

Post by Thierry » Wed Mar 19, 2014 5:27 pm

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Execute a shell script file

Post by Mag » Wed Mar 19, 2014 10:33 pm

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.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Execute a shell script file

Post by Thierry » Thu Mar 20, 2014 7:48 am

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Mag
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 802
Joined: Fri Nov 16, 2012 10:51 pm

Re: Execute a shell script file

Post by Mag » Fri Mar 21, 2014 10:50 am

Hi Thierry, thank you so much for your help and very useful advice. Much appreciated!

Post Reply