Sponsored Content
Top Forums Programming Global variable in for loop (BASH) Post 302884329 by Akshay Hegde on Monday 20th of January 2014 05:08:36 AM
Old 01-20-2014
Quote:
Originally Posted by shadyuk
Hello,

I'm trying to read the variable "pause" from a for loop without luck. The function is dependant on the outcome of the test within the loop. If i run this, pause is always 0 within the function. Any ideas?

Thanks.

Code:
pause=0
user=1

(for (( ; ; ))
do
   speed=`cat speed.log`
   if [ "$speed" -lt 10 ]; then
      pause=1
   else
      pause=0
   fi
sleep 30
done) &

function user () {
   local user=$1   
   while [[ "$pause" = 1 ]; do
      echo pausing script
      sleep 10
   done
   # else continue
}

for (( user = 1; user <= $users; user++ )); do
  one_user $user &
done

Correct it

while [ "$pause" -eq 1 ]; do

--edit---

I didn't understand what's your aim ? where you are breaking loop ?

Last edited by Akshay Hegde; 01-20-2014 at 06:13 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

bash and ksh: variable lost in loop in bash?

Hi, I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Discussion started by: estienne
2 Replies

2. Shell Programming and Scripting

Global variable value

Hi All, Im new to shell scripting. I am running EgA.sh and setting one global variable XYZ=0 . Also calling another EgB.sh from EgA.sh, changing the value of XYZ=10 but after executing EgB.sh, value of XYZ is still 0. Im expecting it to be 10. Anyone for help. Thanks in Advance. :) (5 Replies)
Discussion started by: paliwal
5 Replies

3. Shell Programming and Scripting

(BASH) Using a loop variable to grep something in a file?

Hi, I have a loop running until a variable L that is read previously in the full script. I'd like to grep some information in an input file at a line that contains the value of the loop parameter $i. I've tried to use grep, but the problem is nothing is written in the FILE files. It seems grep... (5 Replies)
Discussion started by: DMini
5 Replies

4. UNIX for Dummies Questions & Answers

Help with 3 variable bash loop

Hi all! I think someone might be able to solve my problem pretty easily. I am trying to run a bash loop with 3 variables. I know how to do: for var1 in `cat list1`; do for var2 in `cat list2`; do for var3 in `cat list3`; command var1 var2 > var3; done; done; done However, this will run all... (4 Replies)
Discussion started by: torchij
4 Replies

5. Shell Programming and Scripting

Detail on For loop for multiple file input and bash variable usage

Dear mentors, I just need little explanation regarding for loop to give input to awk script for file in `ls *.txt |sort -t"_" -k2n,2`; do awk script $file done which sorts file in order, and will input one after another file in order to awk script suppose if I have to input 2 or... (4 Replies)
Discussion started by: Akshay Hegde
4 Replies

6. Shell Programming and Scripting

Bash for loop with arrays second variable?

I am fairly new to bash and am not sure how to resolve this: I have a series of geographical long/lat points eg. 50/-30 listed on separate lines in a file called junk2. I have input these into an array and am then using that array in a for loop. Towards the end of the loop I create a file called... (4 Replies)
Discussion started by: lily-anne
4 Replies

7. Shell Programming and Scripting

Unable to set Global variable outside while loop

Below is my code: count=0 if ... ... else ... find * -prune -type d | sort -r -n | while read d; do count=1 if ; then echo "Count1:$count" ... ... break 2; fi ... done ... fi echo "Count2:$count" (9 Replies)
Discussion started by: mohtashims
9 Replies

8. Shell Programming and Scripting

Bash variable available for use outside loop

In the below for loop, I extract a variable $d which is an id that will change each time. The bash executes the problem that I am having is that p (after the done) is the path with the extracted $d. However, I can not use it in subsequent loops as it is not reconized. I have been trying to change... (3 Replies)
Discussion started by: cmccabe
3 Replies

9. UNIX for Beginners Questions & Answers

How do I assign the output of a command to a variable within a loop in bash?

In the else of the main if condition . else set lnk = $(readlink -f <path> | cut -d '/' -f7) echo "$lnk" if ] When I run the above on command line , the execution seems to be fine and I get the desired output. But when I try to assign it to a variable within a loop... (12 Replies)
Discussion started by: sankasu
12 Replies

10. UNIX for Beginners Questions & Answers

Bash Variable scope - while loop while reading from a file

Cope sample1: test.sh i=0 echo " Outside loop i = $i " while do i=$(( $i + 1)) echo "Inside loop i = $i " done echo " Out of loop i is : $i " When run output : Outside loop i = 0 Inside loop i = 1 Inside loop i = 2 Inside loop i = 3 Inside loop i = 4 Inside loop i = 5 Inside... (8 Replies)
Discussion started by: Adarshreddy01
8 Replies
tracker-status(1)						   User Commands						 tracker-status(1)

NAME
tracker-status - Report the state of all data miners SYNOPSIS
tracker-status [OPTION...] DESCRIPTION
tracker-status shows the status of all miners installed. It also allows pausing and resuming of miners. For tracker-store state, you need to use tracker-control OPTIONS
-?, --help Show summary of options. -f, --follow Follow status changes as they happen. This requires Ctrl+C to stop and return to the command line. Each new status is put on a new line. To get more information, you can use --detailed with this. -d, --detailed For the most part, this purely provides a timestamp with each status update to follow WHEN changes happened. -s, --list-common-statuses This will list statuses most commonly produced by miners and the store. These statuses are not translated when sent over D-Bus and should be translated by each application. These are not considered static and are subject to change at any point. Additionally, these statuses are not the only ones which may be reported by a miner. There may be other states pertaining to the specific roles of the miner in question. -l, --list-miners-running This will list all miners which have responded to a D-Bus call. Sometimes it is helpfult to use this command with --list-miners- available. -a, --list-miners-available This will list all miners which are available even if they are not running at the moment. -i, --pause-details For listing all miners which are paused and the reasons for being paused, you can use this. It will also display the application that requested the pause too. -m, --miner=MINER This argument is used with --pause and --resume to say which miner you want to pause or resume. You can use the full D-Bus name, e.g. org.freedesktop.Tracker1.Miner.Files OR you can use the suffix, e.g. Files -p, --pause=REASON The REASON here is useful to know WHY the miner should be paused. A miner can be paused many times by multiple applications. Only when all pauses have been resumed will it continue. If successful, a cookie will be given to uniquely identify the request. This cookie is used to resume the pause at a later stage. -r, --resume=COOKIE The COOKIE is given by a successful --pause command. It is a number which identifies each pause request. When all pauses have been resumed, the miner will resume working. -V, --version Print version. SEE ALSO
tracker-store(1), tracker-stats(1), tracker-control(1) GNU
July 2009 tracker-status(1)
All times are GMT -4. The time now is 08:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy