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.. |
command line parameters
|
sorry what do you mean? could you elaborate?
|
Quote:
1. Pass argument on the command line: Code:
shell_script_name arg arg arg 2. Invoke one shell script within another like this: Code:
. script-name (see the dot at the left?) 3. Piping: Code:
script_1 | script_2 | script_3 This doesn't exhaust the possibilities, but it should give you some ideas. |
pass the vaiables as parameters to the other shell script
like ./script2.sh var1 var2 var3 |
#!/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 |
yes
you have to change the child shell script to read the command line and store it in new variables |
so how would i use them.. im still getting errors
here is the code MAIN Code:
#!/bin/bash here is DRWPACMAN Code:
#!/bin/bash |
replace the variable names with $? where ? is a number from 1-9
some other member will help i really dont have time |
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 |
All times are GMT -5. The time now is 04:05 PM. |