LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-09-2007, 05:51 PM   #1
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
Bash scripting silly question


hello.. I've found a way to increase lets say a counter... but I think my way is stupid, there must be better solution...

Code:
hey=1
hey=`echo $hey+1 | bc`
I think the best way is something like hey={$$hey}+1
but I'm not familiar with the right syntax.


Thanks.
 
Old 05-09-2007, 05:58 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
What about
Code:
let hey+=1
 
Old 05-09-2007, 05:59 PM   #3
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Alternative:
Code:
hey=$(($hey+1))
 
Old 05-09-2007, 07:24 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
If it is a loop counter, you can use this form of the "for" command:

for (( index=100; index<200; index++ )); do
 
Old 05-09-2007, 07:32 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Oh, I completely forgot about
Code:
let hey++
 
Old 05-09-2007, 07:57 PM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
The old (and more portable) way :
Code:
hey=`expr $hey + 1`
 
  


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
Bash Scripting: Question About tr tvynr Linux - Software 16 09-01-2006 07:25 AM
Bash scripting question nitroid Programming 3 04-13-2006 07:08 AM
silly bash question bennethos Programming 1 03-25-2006 09:46 AM
Bash Scripting Question jsimmonds Programming 2 06-16-2005 09:07 AM
silly bash/aterm ctrl+l question jipe Linux - General 0 01-05-2004 06:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:42 PM.

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