LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-15-2013, 01:23 AM   #1
antriksh
Member
 
Registered: Aug 2010
Location: In my world
Distribution: Oracle Linux 6
Posts: 81

Rep: Reputation: 0
Question 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
 
Old 01-15-2013, 01:27 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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/

Last edited by chrism01; 01-15-2013 at 01:28 AM.
 
Old 01-15-2013, 01:42 AM   #3
antriksh
Member
 
Registered: Aug 2010
Location: In my world
Distribution: Oracle Linux 6
Posts: 81

Original Poster
Rep: Reputation: 0
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.
 
Old 01-15-2013, 01:45 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
I don't quite understand why you use the echo command at all, why don't you use the ps command directly?
 
Old 01-15-2013, 01:46 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
As per TobiSGD; no need to use 'echo', just use the 'ps -ef' directly.
 
Old 01-15-2013, 01:51 AM   #6
antriksh
Member
 
Registered: Aug 2010
Location: In my world
Distribution: Oracle Linux 6
Posts: 81

Original Poster
Rep: Reputation: 0
Yes..thanks..silly mistake.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script to perform more than one command stevo520 Linux - Newbie 6 06-24-2012 10:43 AM
My ubuntu 10.04 restarts as i perform a certain task adam.athumani Linux - Newbie 1 08-24-2010 08:54 PM
for shell script how to store the output of another task other than this command self vvpp Linux - Newbie 11 11-13-2009 01:28 AM
script doesn't perform the same as task done by hand bradvan Linux - Server 2 03-31-2009 11:00 AM
helping me in a bash script that perform a "select" menus Task adam_blackice Programming 5 09-15-2007 02:09 PM


All times are GMT -5. The time now is 04:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration