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 27 Nov 2014, 05:28
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 Posts_count  
Author Message
Argolance


Joined: 06 Jan 2008
Posts: 1847
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.

Edited_time_total
Back to top
View user's profile Send_private_message Visit_website 
SFR


Joined: 26 Oct 2011
Posts: 1101

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: 1847
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.

Edited_time_total
Back to top
View user's profile Send_private_message Visit_website 
Argolance


Joined: 06 Jan 2008
Posts: 1847
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_website 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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