LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 10-02-2009, 11:33 PM   #1
xskycamefalling
Member
 
Registered: May 2009
Posts: 43

Rep: Reputation: 15
pass variable from one shell script into another shell script


so this might be a stupid question im not sure.. im still a bit new to all of this

i have some messy code that i wrote a while back and im trying to organize it..

the program opens xpaint and uses xwit and xte to draw packman and so on..

i want to split it all up im going to add more to it..

basically like i would want drawing packman in one function i guess you could call it and then coloring him or the backround in another


<code>
#!/bin/bash
pkill xpaint
res=`xwininfo -root | grep geom | sed -e 's/^.*try \([0-9][0-9]*x[0-9][0-9]*\)+.*$/\1/'`
Xoriginal=`echo $res | cut -d 'x' -f 1`
Yoriginal=`echo $res | cut -d 'x' -f 2`

X=`echo "($Xoriginal/2)-400" | bc `
Y=`echo "$Yoriginal/2" | bc `
#t=$(($Y/2))
bob=`echo "$Y/2" |bc `



echo $X
echo $Y

/usr/bin/xpaint -size "$Xoriginal"x"$Yoriginal" -popped &
sleep 4
paintersMom=`xwit -all -print | grep XP | cut -d ":" -f 1`
canvasWin=`xwit -all -print | grep Untitled | cut -d ":" -f 1`
#toolres=`xwininfo -id $paintersmom | grep geom | sed -e 's/^.*try \([0-9][0-9]*x[0-9][0-9]*\)+.*$/\1/'`
#canres=`xwininfo -id $canvasWin | grep geom | sed -e 's/^.*try \([0-9][0-9]*x[0-9][0-9]*\)+.*$/\1/'`

#echo $paintersMom
xwit -id $paintersMom -move 0 0
xwit -id $canvasWin -move 0 0
xwit -root -warp "$X" "$Y"
sleep 4

for((i=45; i < 315; i++))
do
xte 'mousedown 1'
ang=`./deg2rad $i`

movex=`echo "$X+$bob*c($ang)" | bc -l`
movey=`echo "$Y+$bob*s($ang)" | bc -l`
xwit -root -warp "$movex" "$movey"
done
xwit -root -warp "$X" "$Y"

xte 'mouseup 1'




#xwit -id $paintersMom -focus -raise
#sleep 1
#xwit -id $paintersMom -warp 30 390 #// fill in command on tool bar
#sleep 1
#xte 'mouseclick 1'
#sleep 1
#xwit -id $canvasWin -warp 221 40 #// color selection
#sleep 1
#xte 'mouseclick 1'
#sleep 1
#xwit -id $canvasWin -warp "$(($X-150))" "$Y" #//location on pac man
#sleep 1
#xte 'mouseclick 1'
#sleep 1





#xwit -id $canvasWin -warp 62 44 #// selecting color black
#sleep 1
#xte 'mouseclick 1'
#sleep 1
#xwit -root -warp 62 120 #// selecting back to canvas
#sleep 1
#xte 'mouseclick 1' #// color canvas black
#sleep 1
#xwit -id $paintersMom -focus -raise
#xwit -id $paintersMom -warp 27 108 #//click back to pencil
#sleep 1
#xte 'mouseclick 1'
#sleep 1




</code>


ok so here for example $paintersmom is would be in the drawing of pacman but i would also want to use it when i colored him in.. but i would want both processes in a diffrent shell script


thanks in advance sorry i cant explain this very well..
 
Old 10-02-2009, 11:35 PM   #2
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,234

Rep: Reputation: 189Reputation: 189
command line parameters
 
Old 10-02-2009, 11:35 PM   #3
xskycamefalling
Member
 
Registered: May 2009
Posts: 43

Original Poster
Rep: Reputation: 15
sorry what do you mean? could you elaborate?
 
Old 10-03-2009, 12:04 AM   #4
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by xskycamefalling View Post
sorry what do you mean? could you elaborate?
One shell script has number of ways to communicate with another.

1. Pass argument on the command line:

Code:
shell_script_name arg arg arg
(The second shell script receives these arguments as $1, $2, etc..)

2. Invoke one shell script within another like this:

Code:
. script-name (see the dot at the left?)
Invoking a script like this causes the declared variables from the invoked script to be inherited by the parent script.

3. Piping:

Code:
script_1 | script_2 | script_3
script_1 prints some information, which is piped to script_2, etc..

This doesn't exhaust the possibilities, but it should give you some ideas.
 
1 members found this post helpful.
Old 10-03-2009, 12:15 AM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,234

Rep: Reputation: 189Reputation: 189
pass the vaiables as parameters to the other shell script
like ./script2.sh var1 var2 var3
 
Old 10-03-2009, 12:41 AM   #6
xskycamefalling
Member
 
Registered: May 2009
Posts: 43

Original Poster
Rep: Reputation: 15
#!/bin/bash


pkill xpaint

# get monitor size

res=`xwininfo -root | grep geom | sed -e 's/^.*try \([0-9][0-9]*x[0-9][0-9]*\)+.*$/\1/'`
#
#get x and y value from monitor size

Xoriginal=`echo $res | cut -d 'x' -f 1`
Yoriginal=`echo $res | cut -d 'x' -f 2`
#
#finds center of screen -400 to move pacman to left
X=`echo "($Xoriginal/2)-400" | bc `
Y=`echo "$Yoriginal/2" | bc `
#
#
bob=`echo "$Y/2" |bc `

#
#call xpaint loader
./loadxpaint
#
#call pacman drawer
./drwpacman $Yoriginal $Xoriginal $X $Y $bob



is this what your saying??

./drwpacman $Yoriginal $Xoriginal $X $Y $bob
 
Old 10-03-2009, 01:03 AM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,234

Rep: Reputation: 189Reputation: 189
yes
you have to change the child shell script
to read the command line and store it in new variables
 
Old 10-03-2009, 01:14 AM   #8
xskycamefalling
Member
 
Registered: May 2009
Posts: 43

Original Poster
Rep: Reputation: 15
so how would i use them.. im still getting errors

here is the code

MAIN
Code:
#!/bin/bash


pkill xpaint

# get monitor size

   res=`xwininfo -root | grep geom | sed -e 's/^.*try \([0-9][0-9]*x[0-9][0-9]*\)+.*$/\1/'`
#
#get x and y value from monitor size

   Xoriginal=`echo $res | cut -d 'x' -f 1`
   Yoriginal=`echo $res | cut -d 'x' -f 2`
#
#finds center of screen -400 to move pacman to left
   X=`echo "($Xoriginal/2)-400" | bc `
   Y=`echo "$Yoriginal/2" | bc `
#
#
   bob=`echo "$Y/2" |bc `

#
#call xpaint loader
   ./loadxpaint
#
#call pacman drawer
   ./drwpacman $Yoriginal $Xoriginal $X $Y $bob


~

here is DRWPACMAN


Code:
#!/bin/bash
#
#for loop for circle
. main
xte 'mousedown 1'
for((i=45; i < 315; i++))
do
ang=`./deg2rad $i`

movex=`echo "$X+$bob*c($ang)" | bc -l`
movey=`echo "$Y+$bob*s($ang)" | bc -l`
xwit -root -warp "$movex" "$movey"
done
xwit -root -warp "$X" "$Y"
xte 'mouseup 1'
 
Old 10-03-2009, 01:23 AM   #9
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,234

Rep: Reputation: 189Reputation: 189
replace the variable names with $? where ? is a number from 1-9
some other member will help i really dont have time
 
Old 10-03-2009, 02:45 AM   #10
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
The target-independent way to do this is to export the variables when assigning them; that way bash adds them to the process' environment rather than merely to the one the shell maintains itself, making it available within the fork's environment when the second script is executed.
Kevin Barry
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass command-line parameter to shell script? Kropotkin Linux - Newbie 12 07-25-2011 10:24 AM
Shell script help: How to pass a directory path to the script? dv502 Programming 13 09-10-2008 04:07 AM
pass php variables to shell script viveksnv Programming 1 03-05-2008 12:46 AM
PHP pass argument to shell script monzter Programming 2 08-14-2004 07:16 AM


All times are GMT -5. The time now is 12:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration