ElAdnan / gtkdialog

Automatically exported from code.google.com/p/gtkdialog
GNU General Public License v2.0
0 stars 0 forks source link

function () and Ubuntu... #24

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,
I say, thank you again for all your work on gtkdialog,
it's wonderful:)

Do you have any idea why in Ubuntu "function xxx () {....}" do not work?
apparently "export -f now" does not work,
Perhaps because of the default shell is dash by default?
ls -l $(which sh)
lrwxrwxrwx 1 root root 4 2011-08-12 19:55 /bin/sh -> dash

this code:

#!/bin/bash
function now () {
date > /tmp/date
}
export script='
<vbox>
<entry>
<variable>ENTRY_DATE</variable>
<input>cat /tmp/date</input>
</entry>
<button>
<label>Refresh</label>
<action>now</action>
<action>refresh:ENTRY_DATE</action>
</button>
</vbox>'
export -f now
gtkdialog3  -p script

return: sh: now: not found
sorry for my bad english ...
François

Original issue reported on code.google.com by frafas...@gmail.com on 13 Aug 2011 at 10:43

GoogleCodeExporter commented 8 years ago
This bug is very old ...
https://bugs.launchpad.net/ubuntu/+source/gtkdialog/+bug/517065
François

Original comment by frafas...@gmail.com on 13 Aug 2011 at 11:04

GoogleCodeExporter commented 8 years ago
I have left thunor a private message on Murg-linux.com/puppy concerning this 
issue as I did a little rewrite of the submitted script and it works just fine 
for me.
johnmeyer126@gmail.com  That is 8-bit on the Puppy forum. 

Original comment by johnmeye...@gmail.com on 14 Aug 2011 at 9:08

GoogleCodeExporter commented 8 years ago
If frafas changes the line date > /tmp/date
to echo $ENTRY_DATE > /tmp/date
and the line <input>cat /tmp/date</input>
to <input>date</input>
His example will run fine.
The main reason is that the date command does not accept any parameters and so 
is attempting to see the "> /tmp/date" as a parameter.
That is the best I can explain it.

Original comment by johnmeye...@gmail.com on 15 Aug 2011 at 2:15

GoogleCodeExporter commented 8 years ago
Yess :)
solved "export -f" are ok
use this:
<action>exec $SHELL -c 'now'</action>

Exemple:

#!/bin/bash
function now () {
date > /tmp/date
}
export -f now
export script='<vbox>
<entry>
<variable>ENTRY_DATE</variable>
<input>cat /tmp/date</input>
</entry>
<button>
<label>Refresh</label>
<action>exec $SHELL -c 'now'</action>
<action>refresh:ENTRY_DATE</action>
</button>
</vbox>'
gtkdialog3  -p script
exit 0

Original comment by frafas...@gmail.com on 16 Aug 2011 at 10:14

GoogleCodeExporter commented 8 years ago
Hi

Firstly I've been busy so sorry for the delay. I saw the private message from 
8-bit but had absolutely no idea what he was talking about since the subject 
said "Issue 23" when this is issue 24 :D

That "bashims" issue on launchpad was fixed months ago.

I found this at https://wiki.ubuntu.com/DashAsBinSh :

function

The function builtin is a bashism, and can almost always simply be removed. If 
you remove it, make sure that there are parentheses after the function name. A 
function definition in POSIX shell looks like this:

function_name () {
    function body
}

So, possibly you must remove "function". I have seen this reported elsewhere so 
I will avoid using it in the future.

Regards,
Thunor

Original comment by thunor...@hotmail.com on 16 Aug 2011 at 3:27

GoogleCodeExporter commented 8 years ago
thunor,
  Sorry for the confusion in my PM.  When I realized the issue was not the right one and went to edit it, you had already got the PM.

frafas, 
  If you want your script to show the date and create the /tmp/date file on starting, just add the line $SHELL -c 'now' between the 2 export lines.
And thank you for showing me another way to execute an external command from an 
<action> line.

Original comment by johnmeye...@gmail.com on 16 Aug 2011 at 3:55

GoogleCodeExporter commented 8 years ago
Right, so the conclusion is that the "function" keyword and "export -f 
funcname" aren't supported by dash and that dash is used as the subshell on 
Ubuntu and as the C system() function executes /bin/sh, if that doesn't point 
to bash you'll need to use <action>bash -c funcname</action> or something along 
those lines (<input> commands too).

Anyway, since C's POSIX system() function executes /bin/sh, this really should 
be something to address within the shell script and Gtkdialog XML structure. I 
could create a Gtkdialog command-line argument so that the command passed to 
system() is prepended with "bash -c " or whatever the user supplies, but then 
this can be managed just as effectively from the shell script, example:

EXECBASH="bash -c"
...
<action>$EXECBASH funcname</action>

Original comment by thunor...@hotmail.com on 22 Aug 2011 at 11:18

GoogleCodeExporter commented 8 years ago

Original comment by thunor...@hotmail.com on 6 Sep 2011 at 11:20