LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to perform var++ task in shell script? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-perform-var-task-in-shell-script-4175445650/)

antriksh 01-15-2013 12:23 AM

How to perform var++ task in shell script?
 
Hi..i've a script in which i want to increase value by 1 of a variable and then assign it back to same variable..

For example: flag=flag+1

how to do that?
Code:

flag=1
while [ flag -le 5 ]
do
echo `ps -ef`
sleep 30
# flag++ [need code for this]
done


chrism01 01-15-2013 12:27 AM

Code:

flag=1
while [ flag -le 5 ]
do
echo `ps -ef`
sleep 30
((flag++))
echo $flag  # just to check :)
done

Useful links
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

antriksh 01-15-2013 12:42 AM

Thanks it worked..:)
One more question here i am trying to display system processes every 30 seconds but using echo the output is not coming line by line..can you tell me how to do that? like what we see in normal execution of ps -ef in shell.

TobiSGD 01-15-2013 12:45 AM

I don't quite understand why you use the echo command at all, why don't you use the ps command directly?

chrism01 01-15-2013 12:46 AM

As per TobiSGD; no need to use 'echo', just use the 'ps -ef' directly.

antriksh 01-15-2013 12:51 AM

Yes..thanks..silly mistake.


All times are GMT -5. The time now is 11:40 AM.