Programming :: Pass Variable From One Shell Script Into Another
Oct 2, 2009
I have some messy code that I wrote a while back and I am 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 I am 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 background 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>
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 different shell script.
View 15 Replies
ADVERTISEMENT
Aug 2, 2011
Code...
I am somewhat confident that there is a neater way.
Question: Does anybody know the answer?
View 3 Replies
View Related
Dec 23, 2010
I have the following code :
Code:
E_BADARGS=65
if [ $# -ne 2 ] ; then
[code]...
View 1 Replies
View Related
Mar 9, 2011
I need to pass variable from sc1.sh to sc2.sh and update the value of the passed variable in sc2.sh and then return the updated value of the variable from sc2.sh to sc1.sh.
View 7 Replies
View Related
Dec 4, 2010
i want to pass variable in mysql qyery in c programming
View 1 Replies
View Related
Apr 17, 2009
I'm trying to pass a path as a string to an array, but its evaluating it as a command instead. I want to take the literal string "/mnt/accounts/user/temp/*.jpg" and assign it to an array{1}, but when i echo the array variable, it displays it as
pic1.jpg
pic2.jpg
pic3.jpg
[code]....
I just want it to be the actual text "/mnt/accounts/user/temp/*.jpg" which i will be combining with other text to create a longer path elsewhere in the code.
View 5 Replies
View Related
Dec 20, 2010
This is a section on a php file running within a a Joomla module. I have the following code:
Code:
<?php echo '</div>'; ?>
<html>
[code]....
View 2 Replies
View Related
May 4, 2010
I'm trying to create a program that would locate the oldest file of a certain type on a server. Here's the commands:
OLDEST_PATH=`find -L / -depth -maxdepth 6 -mindepth 6 -type d | sort -f | head -1`
OLDEST_FILE=`find -L $OLDEST_PATH | grep .mp3 | sort -f | head -1`
ls -al $OLDEST_FILE
I'm writing this all in expect but I'm having problems. The main problem I have is whenever I try to run the first command, I can't seem to isolate the result of the OLDEST_PATH so that the 2nd command will work. There always seems to be a newline in the variable and the result is only "find -L" command running and it bypasses the variable. If I can just figure out how to get the 1st and 2nd command to work, then I can figure out the 3rd. Here's some code:
Code:
send "find -L / -depth -maxdepth 6 -mindepth 6 -type d | sort -f | head -1
"
sleep 20
expect -re "(.*)
[Code]....
I know there is a better way to write this. I've tried multiple ways and this just happens to be the last way I've tried it. If you try running this, you'll notice that there is still carriage returns after the result of OLDEST_PATH and it prevents the 2nd "find" command from working properly.
View 2 Replies
View Related
Jan 25, 2011
I'm trying to write a python script that will use the current user's name when interacting. Ex: when started, it should say "hello daweefolk" when I am logged in.
I've tried
Code:
username=os.system("echo $USER")
but the variable remains empty.
What is the correct code?
View 1 Replies
View Related
Apr 28, 2010
included shell script inside c program, and i wanted to assign the value of c variable to shell variable..Can any one please suggest me how to do it?
View 8 Replies
View Related
Jul 23, 2010
I have been searching most of today and am stuck on getting a variable into an awk portion of my bash script. I have this working:
Code:
#!/bin/sh
SRC=/var/log/mail.log
DEST=/var/www/output/myFile.txt
VAR=userName@myDomain.tld
[code]....
Can awk take a shell variable? Or do I have to do something completely different?
View 11 Replies
View Related
Oct 7, 2009
I'm new to UNIX scripting; I�m stuck with the following I have an Oracle SQL script that takes three parameters
1- File Name
2- File Path
3- File creation date
Under UNIX I have a folder where files will be placed frequently and I need to upload those files to Oracle, what I need is a UNIX script that can do the following
Loop through Directory "/home/applmgr/snktmp"
Picks only files
Pass the file name to parameter &1
[code]....
Is the above possible? I already knows how to call the Oracle Script from UNIX Im only stuck on writing the UNIX part where it List the files attribute(name,path,date) and store them to parameters ,Looping until the last file in the directory If the above is not possible,then how can I create the below from the command line
Filename{concatenation Mark}filePath{concatenation Mark}creationdate
Filename{concatenation Mark}filePath{concatenation Mark}creationdate
Filename{concatenation Mark}filePath{concatenation Mark}creationdate
Filename{concatenation Mark}filePath{concatenation Mark}creationdate
View 4 Replies
View Related
May 4, 2010
Using things like awk/sed, but have managed to cobble together what I needed so far without a problem. The only thing I'm struggling with is to assign the content of a particular line as a variable, and then to use it again throughout the file.
For example, if what I want is the first line of the file to become the variable "from1", and then to replace the word "Subject" in the file with the string "Message from [from1]". What I thought would work
I tried a few diff combinations but nothing seems to work. All I get is the terminal hanging indefinitely.
View 3 Replies
View Related
Jan 20, 2011
What I am trying to accomplish is a way to read only the lines that have been added to the file mylog0 since the last time the script looped (5 seconds). I am open to new suggestions too, I have been stuck on this little script for a few hours already.
Code: #!/bin/bash
i=0
firstline=0
[code]...
View 2 Replies
View Related
Nov 10, 2010
Code:
grep -r $SEARCHDIR --include="day_$YYYY-$MM-*" -h -o -e PATTERN
The above command does exactly what I want: limit the search of files in $SEARCHDIR to those specified by --include.
I use double quotes rather than single quotes because of the shell variables. I would have thought this would cause the shell to expand the "*" but this doesn't seem to be the case.
View 1 Replies
View Related
Oct 28, 2010
I am trying to map the coordinates of a grid.
Code:
R=7 # number of rows (lines)
C=6 # number of columns
X=200 # initial horizontal location
Y=100 # initial vertical location
[code]....
View 4 Replies
View Related
Jul 25, 2011
I'm using sed to remove certain line in a text file based on a match with 2 variables from input. Here is how it looks like in file
Philip S:Odds:45:343
Mike Junior:Odds:3:56
I prompt for 2 inputs in variable form which is compared to the first 2 fields of the above text (: seperated). So say i enter Philip S and Odds then it should delete the entire first line.
View 4 Replies
View Related
Mar 28, 2009
I need to check whether a shell script variable contains non-zero numeric data to proceed. The variable should contain numeric values, but may in fact contain zeroes, blank space or nothing. So far, I have tried various combinations of:
Code:
if test $variable
then
if test $variable -gt 0
then
echo "good data exists"
else "no good data exists"
fi
fi
It partially works, but I get either "too many arguments" or "integer expression expected".
View 2 Replies
View Related
Nov 22, 2009
I want to pass a variable from one script to another, I have a feeling it's extremely simple.
I looked at exporting, but apparently that clogs up the shell, so I don't want to go down that route. Any suggestions?
View 2 Replies
View Related
Jul 28, 2010
What i want to do is create multiple informix sql statements & later run them via a bash script.
Here is what i have so far (this works) but is meant to be run from a cron job so it only does one day at a time:
echo "
update hst`date --date='yesterday' +%m%d%y`
set x = 'GARP'
where y in ('CRE', 'LAC', 'SRL', 'JAG', 'JNM', 'BIM')
and appl = '';
[Code].....
The problem here is it doesnt want to read the variable $x correctly so the statement fails.
View 1 Replies
View Related
Sep 8, 2010
I have a line that looks something like this:
Code:
How do i put its output in a variable?
View 9 Replies
View Related
Feb 23, 2010
I am trying to pass a variable to smbclient (OS X), but the variable is recognized only as its strict text.
Is there anything syntactically I have to do pass a variable created in the shell (bash) to smbclient (or perhaps any other interactive app)? I've seen references to variables as $[variable] or ${variable} but I've not been able to figure out what works.
View 5 Replies
View Related
Feb 11, 2010
I am trying to write a script that will find any user on the server running more than one instance of the epiphany web browser process, then kill all their epiphany pids. (This is necessary sometimes to cure lockups, and repeat processes are the telltale sign in this case). I have tried implementing the until loop:
Code:
USER=`ps aux | grep epiphany | grep -v grep | sort | uniq -d -w 5 | awk '{print $1}'`
until [[ "$USER" == "" ]]
do
ps aux | grep epiphany | grep -v grep | grep $USER | awk '{print $2}' | sudo xargs kill
done
Unfortunately, the script only calculates the USER variable once at the beginning of the script. Fair enough, that's how it's written. My question is, how would I get the USER variable to update for each pass of the until loop so that it could cure multiple users of this ailment if necessary? That is, calculate $USER, kill their epiphany pids, repeat those two steps until the $USER variable comes up blank, then exit.
View 5 Replies
View Related
Apr 26, 2010
I am not parsing on a webserver so is it possible to have both
#! /usr/bin/php &
#!/bin/bash
in the same script? Alternatively, I have a current bash script that I need to get some variables from mysql and not sure how to get mysql results in bash:
Quote:
mysql -h server.net -u username1 -paaa -e "USE squid; SELECT email, usern FROM TABLE WHERE blah blah;"
emailadd="resultfrom above"
usern="resultfromabove"
View 11 Replies
View Related
May 21, 2009
Is there a way to export a variable to parent shell in shell scripting ?
View 3 Replies
View Related
May 2, 2010
I am looking for a clue in shell or ant script, where I excecute a binay file on linux. For example ./myfile.bin which ask me few questions.
./myfile.bin ...........................100%
I would like to automate this process where I want to pass the hostname as a variable or read from a file is it possible? If yes any sample`s on this. I can do if this was a shell script ($1) but not sure when its binary.
View 8 Replies
View Related
Aug 21, 2009
I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.
For example:
Code:
Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).
View 6 Replies
View Related
Jun 16, 2011
Why does this work
Code:
for myfile in `find . -name "R*VER" -mtime +1`
do
[code]...
View 2 Replies
View Related
Apr 7, 2010
my script has a variable which comes in the form +00.00 +0.00 -00.00 or -0.00 (the numbers can be any in that form) for any that have a + symbol I need to remove the +, but if it has a - symbol it needs to stay.
i need to make a new variable with the string from the old variable btut without any plus sign. I have tried a lot of different ways with no success, each thing I tried either left the + or removed the entire string. I think this should work but doesn't
foo=+12.40
bar=${foo#+}
View 4 Replies
View Related
Apr 25, 2011
how I can search within a variable and assign the results to a new variable. I'll use the following as an example -
cars="Audi BMW Cadillac Chevy Dodge Ferrari Ford Mercedes"
list=`echo ${cars} | egrep -o '<A?+|<C+'`
with the echo command I get the following output assigned to list -
A
C
C
What I'd like to get for output is -
Audi
Cadillac
Chevy
how I could do this regardless of upper/lower case letters?
View 5 Replies
View Related