Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 23 Oct 2014, 14:18
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Variable inside a function? [SOLVED]
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [4 Posts]  
Author Message
Argolance


Joined: 06 Jan 2008
Posts: 1836
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Wed 20 Mar 2013, 08:31    Post subject:  Variable inside a function? [SOLVED]  

Bonjour,
How to make the variable "DEF_APP" to work inside this function?
Example:
Code:
#!/bin/sh

export DEF_APP="myapp"

func_defaultapp () {

   Xdialog --title "$(gettext 'Installation') - $(gettext 'Information')" icon /usr/local/lib/X11/pixmaps/question.png --stdout --yesno "$(gettext 'Do you want this application to be set as default?')" 0 0

   case $? in
      0)echo '#!/bin/sh
      
exec $DEF_APP "$@"' > /root/defaultapptest
      ;;
      1)Xdialog --title "$(gettext 'Installation') - $(gettext 'Information')" --no-buttons --infobox "$(gettext 'Canceled...')" 3 50
      ;;
      255)Xdialog --title "$(gettext 'Installation') - $(gettext 'Information')" --no-buttons --infobox "$(gettext 'Canceled...')" 3 50
      ;;
   esac
}
export -f func_defaultapp

func_default

I get:
Code:
#!/bin/sh
      
exec $DEF_APP "$@"

And would like to get:
Code:
#!/bin/sh
      
exec myapp "$@"


Ouch! The variables... Evil or Very Mad Confused
Thank you!

Cordialement.

Last edited by Argolance on Wed 20 Mar 2013, 09:52; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
SFR


Joined: 26 Oct 2011
Posts: 1078

PostPosted: Wed 20 Mar 2013, 09:36    Post subject:  

Single quotes prevent variables from being expanded:
Code:
# var=123; echo 'something $var blahblah'
something $var blahblah
# var=123; echo 'something '$var' blahblah'
something 123 blahblah
#

This should work:
Code:
exec '$DEF_APP' "$@"' > /root/defaultapptest

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
Argolance


Joined: 06 Jan 2008
Posts: 1836
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Wed 20 Mar 2013, 09:44    Post subject:  

Hello, I found the (a) solution:
Code:
#!/bin/bash

export DEF_APP="myapp"

func_defaultapp () {

   Xdialog --title "$(gettext 'Installation') - $(gettext 'Information')" icon /usr/local/lib/X11/pixmaps/question.png --stdout --yesno "$(gettext 'Do you want this application to be set as default?')" 0 0

   case $? in
      0)echo "#!/bin/sh
      
exec $DEF_APP \"\$@\""> /root/defaultapptest
      ;;
      1)Xdialog --title "$(gettext 'Installation') - $(gettext 'Information')" --no-buttons --infobox "$(gettext 'Canceled...')" 3 50
      ;;
      255)Xdialog --title "$(gettext 'Installation') - $(gettext 'Information')" --no-buttons --infobox "$(gettext 'Canceled...')" 3 50
      ;;
   esac
}
export -f func_defaultapp

func_defaultapp

Question: This works but is this right?
Thanks.

Cordialement.

Last edited by Argolance on Wed 20 Mar 2013, 09:52; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
Argolance


Joined: 06 Jan 2008
Posts: 1836
Location: PORT-BRILLET (Mayenne - France)

PostPosted: Wed 20 Mar 2013, 09:51    Post subject:  

... This works (too) and seems to be more "kosher"! Wink
Thanks.

Cordialement.
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [4 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0514s ][ Queries: 12 (0.0043s) ][ GZIP on ]