The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Converting a String variable into Integer neeto UNIX for Dummies Questions & Answers 2 05-22-2008 03:38 PM
Subtracting date / timestamps roadcyclist Shell Programming and Scripting 0 06-21-2006 02:51 PM
Will we get SEGV if we try to “delete []” un-initialized integer pointer variable. sureshreddi_ps High Level Programming 2 10-11-2004 06:11 AM
capturing the output of grep as integer variable babariba UNIX for Dummies Questions & Answers 2 11-16-2001 10:42 AM
Subtracting Variables which are commands Astudent UNIX for Dummies Questions & Answers 2 03-30-2001 09:55 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-10-2008
The Observer The Observer is offline
Registered User
  
 

Join Date: May 2008
Posts: 18
Subtracting an Integer from a Variable

Hello,

I am in following situation.-

COUNT=`ls -l | wc -l`
echo $COUNT
---> 26
NO_OF_FILES=$COUNT-1
echo $NO_OF_FILES
---> 26-1

Here, I want the output to be 25. How could I do this. It seems simple, but I am not getting it. Please help me.
  #2 (permalink)  
Old 06-10-2008
stcroix111 stcroix111 is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 2
use expr to do math.

NO_OF_FILES= expr $COUNT - 1

This should give you what you are looking for.
  #3 (permalink)  
Old 06-10-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
If you only want a file count, you don't need to subtract anything. Just issue:

Code:
COUNT=`ls | wc -l`
If you want to compute calculations and you're using bash, try:

Code:
x=10
x=$((x-1))
echo $x
Otherwise, go with "expr" as said by stcroix111
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0