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 Mon 22 Dec 2014, 01:02
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
A way to get variables back from a function... Needed this!
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
sunburnt


Joined: 08 Jun 2005
Posts: 5043
Location: Arizona, U.S.A.

PostPosted: Wed 21 Apr 2010, 05:01    Post_subject:  A way to get variables back from a function... Needed this!  

I found a way to get variables back out of a function. ( I`m sure others have thought of it...)
Here`s the code, could solve problems with getting variables into gtkdialog from functions:
Code:
guiPOS() {
  G=($(xwininfo -name "$1" |sed '4,9!d'))                          # get size and pos. for GUI
  ((X=G[3]-G[11], Y=G[7]-G[15], W=G[17], H=G[19]))
  ((X<1)) && ((X=0)); ((Y<1)) && ((Y=0)) ; echo "X=$X,Y=$Y,W=$W,H=$H"
}
overPOS() {
   ((`guiPOS $1`))                                                              # get main GUI Left and top
   popX=$(($X+$offX)) ; popY=$(($Y+$offY))                # get X and Y position offsets
}

As long as the function`s returned value is one long string with no spaces it`s OK...
The evaluation parentheses take "," instead of Bashes taking ";" for evaluation separators.
How to "can" this in a library? Another words, make it call just like a function does now.
A fix for Bash`s function, call it like a normal function and get back evaluated variables.
Sort of like having the ". " run in the same shell for functions, I`d call this a big fix.
Back to top
View user's profile Send_private_message 
ken geometrics

Joined: 23 Jan 2009
Posts: 76
Location: California

PostPosted: Fri 23 Apr 2010, 10:55    Post_subject:  

Also:
If you have a list of values to return but don't want to force the names they go into, you can do something like this:

:~> CC="987654 65432"
:~> read AA BB <<-XYZZY
> $CC
> XYZZY
:~> echo "$AA"
987654
:~> echo "$BB"
65432


The $CC gets expanded into the here document. This means you can feed its contents into a command as though it came from a file.
Back to top
View user's profile Send_private_message 
sunburnt


Joined: 08 Jun 2005
Posts: 5043
Location: Arizona, U.S.A.

PostPosted: Fri 23 Apr 2010, 11:26    Post_subject:  

Hi ken geometrics; Your code looks really interesting, I`ve never seen syntax like it...
But I can`t see how it works, could you edit it into a function with it`s call below?
Code:
f() {
# Function code
}
f ARG
# Output code

I assume it`s doing something different than like a function returning a comma delimited string.
echo "$X,$Y,$W,$H"
Back to top
View user's profile Send_private_message 
potong

Joined: 06 Mar 2009
Posts: 88

PostPosted: Sat 24 Apr 2010, 07:05    Post_subject:  

Try these:
Code:

# unset a b c                                                                                                 
# a="b=bbb c=ccc"
# echo $a
b=bbb c=ccc
# eval $a
# echo $a $b $c
b=bbb c=ccc bbb ccc
# unset a b c
# echo $a $b $c

# a="b=bbb c=ccc"
# echo $a >/tmp/a
# . /tmp/a
# echo $a $b $c
b=bbb c=ccc bbb ccc
# unset a b c
# a="b=bbb c=ccc"
# . <<<$a
bash: .: filename argument required
.: usage: . filename [arguments]

N.B. the here-string doesn't work Sad

Potong
Back to top
View user's profile Send_private_message 
sunburnt


Joined: 08 Jun 2005
Posts: 5043
Location: Arizona, U.S.A.

PostPosted: Sat 24 Apr 2010, 14:35    Post_subject:  

Hi potong; Variables within variables, yes... Really nifty is commands within variables!
The gtkinfo code I posted returns an info list of variables of all gtkdialogs within a variable.
Back to top
View user's profile Send_private_message 
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.0500s ][ Queries: 11 (0.0031s) ][ GZIP on ]