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 > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Subtracting an Integer from a Variable The Observer UNIX for Dummies Questions & Answers 2 06-10-2008 12:11 PM
Subtracting date / timestamps roadcyclist Shell Programming and Scripting 0 06-21-2006 02:51 PM
subtracting a days from current date rameshspal Shell Programming and Scripting 1 03-10-2006 01:18 AM
Subtracting Two months from date jwatson12 UNIX for Dummies Questions & Answers 3 09-13-2002 01:06 PM
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
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-09-2008
cesarNZ cesarNZ is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 70
subtracting variables in ksh

hi all,
how do i subract variables in shell ?? am trying to space out the headers and the output generated by the shell so they all line up :

currently the output is like this :


servers : users

server1 : 10
latestServer : 50



so i thought i would keep a constant e.g 40 and subtract the length of the server name from it.

count=${#myserver}; <-- this is the length of the server name
spaces=((40 - $count )); <-- this doesnt really work

thanks in advance.
  #2 (permalink)  
Old 10-09-2008
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,382
you were almost there
Code:
spaces=$((40-$count))
  #3 (permalink)  
Old 10-09-2008
a2156z a2156z is offline
Users Awaiting Email Confirmation
  
 

Join Date: Oct 2008
Posts: 30
((spaces=40-count))
  #4 (permalink)  
Old 10-10-2008
cfajohnson's Avatar
cfajohnson cfajohnson is online now Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,317
Quote:
Originally Posted by a2156z View Post
((spaces=40-count))
That is non-standard. For example:

Code:
$ count=3
$ ((spaces=40-count))
$ printf ":%s:\n" "$spaces"
::
$ spaces=$((40 - $count))
$ printf ":%s:\n" "$spaces"
:37:
Sponsored Links
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 09:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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