LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 12:23 AM   #1
antriksh
Member
 
Registered: Aug 2010
Location: In my world
Distribution: Oracle Linux 6
Posts: 83

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, 12:27 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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 12:28 AM.
 
Old 01-15-2013, 12:42 AM   #3
antriksh
Member
 
Registered: Aug 2010
Location: In my world
Distribution: Oracle Linux 6
Posts: 83

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, 12:45 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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, 12:46 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

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

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


Reply



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 09:43 AM
My ubuntu 10.04 restarts as i perform a certain task adam.athumani Linux - Newbie 1 08-24-2010 07: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 12:28 AM
script doesn't perform the same as task done by hand bradvan Linux - Server 2 03-31-2009 10:00 AM
helping me in a bash script that perform a "select" menus Task adam_blackice Programming 5 09-15-2007 01:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:20 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
Open Source Consulting | Domain Registration