In the cat ... | while read you should see another pid while doing ps -ef | grep <your script pid>.
Another pid will be subshell pid with your script PID as parent.
For instance :
Code:
echo $$
var=0
echo "junk" | while read line
do
sleep 100
((var++))
done
echo $var
Yields :
Code:
user@machine:~/posao$ ./sshell.sh
2775
Code:
user@machine:~/work$ ps -ef | grep 2775
user 2775 2488 0 05:46 pts/0 00:00:00 bash
user 2777 2775 0 05:46 pts/0 00:00:00 bash # var will be incremented in shell with PID 2777, when it completes it will exit, parent (our script with PID 2775) will not be aware of var increment.
user 2782 2528 0 05:46 pts/1 00:00:00 grep 2775
user@machine:~/work$ ps -ef | grep sleep
user 2778 2777 0 05:46 pts/0 00:00:00 sleep 100
user 2784 2528 0 05:46 pts/1 00:00:00 grep sleep
Other example :
Code:
echo $$
var=0
while read line
do
sleep 100
((var++))
done < junk.txt
echo $var
Yields :
Code:
user@machine:~/work$ ./shell.sh
2755
Code:
user@machine:~/work$ ps -ef | grep 2755
user 2755 2488 0 05:40 pts/0 00:00:00 bash
user 2756 2755 0 05:40 pts/0 00:00:00 sleep 100 # after this, var will be incremented in shell with pid 2755 (our script).
user 2759 2528 0 05:41 pts/1 00:00:00 grep 2755
Notice the difference in bash count with parent / children relation in both examples.
okay, this shouldn't be difficult but I can't figure it out. How can I set a variable with another variable. I have the following:
foreach pe ($dir $sp)
set tpe = `echo $pe | grep M`
if ($tpe == M) then
set ${$pe} = M <--- This doesn't work
else
endif
end
In this case what... (2 Replies)
#!/bin/sh
APP_ROOT_MODE1=/opt/app1.0
APP_ROOT_MODE2=/opt/app2.0
APP_ROOT=${APP_ROOT_${APP_MODE}}
# enviornment variable APP_MODE will be exported in the terminal where
# we run the applciation, its value is string - MODE1 or MODE2
# My intension is:
# when export APP_MODE=MODE1... (4 Replies)
I am writing a script to cross check the dbscript. For that I am searching the SQL manipulators in the dbscript as shown below. But my problem is the variable $pattern is coming as null when comes out of the foreach loop.
File content:
=========
vi /home2/niroj_p/dbscript.sql
-------... (1 Reply)
Dear All,
we have a command output which looks like :
Total 200 queues in 30000 Kbytes
and we're going to get "200" and "30000" for further process. currently, i'm using :
numA=echo $OUTPUT | awk '{print $2}'
numB=echo $OUTPUT | awk '{print $5}'
my question is : can I use just one... (4 Replies)
How can I assign a variable to an variable. IE $car=honda
One way I can do it is export $car=honda
or
let $car=2323
Is there any other ways to preform this task (3 Replies)
Hi,
I am trying to do the following thing
var='date'
$var
Above command substitutes date for and in turn runs the date command and i am getting the todays date value.
I am trying to do the same thing as following, but facing some problems,
unique_host_pro="sed -e ' /#/d'... (3 Replies)
Simple enough problem I think, I just can't seem to get it right.
The below doesn't work as intended, it's just a function defined in a much larger script:
CheckValues() {
for field in \
Group_ID \
Group_Title \
Rule_ID \
Rule_Severity \
... (2 Replies)
Hi,
I have Below script which converts csv file to html succesfully.but the visiblity is simple in black n white. I want to have better visibilty of each columns in different colours(like green).As it is a Database report suppose some tablespace available space is less than 20% then it should... (7 Replies)
Does anyone know if it is possible to check whether a window in x11 (using xlib) is visible or not? I tried XGetWindowProperty, but that doesn't work, because the windows host (dtwm on Solaris 10) does not support EWMH. (5 Replies)
I have the following script, and I want to assign the output ($10 and $5) from awk to N and L:
grdinfo data.grd | awk '{print $10,$5}'| read N L
output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)