Sponsored Content
Top Forums Shell Programming and Scripting Modulo calculation in shell script Post 302506506 by frans on Monday 21st of March 2011 04:08:09 AM
Old 03-21-2011
Could be written (with arithmetic evaluation and array)
bash code:
  1. #!/usr/bin/bash
  2. parity=(even odd) # parity[0]='even' parity[1]='odd'
  3. read -p "enter a number: " a
  4. echo "the number is ${parity[$((a%2))]}
This User Gave Thanks to frans For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script math calculation

Hi Gurus, I'm currently using HP-UX B.11.23. I've a simple calculation script which performs the task below. -> echo "240021344 / 1024 /1024" | bc Output: 228 240021344 is KB value. When I tried to perform the same calculate in Ms Excel, it produces a different result: 228.9021912.... (12 Replies)
Discussion started by: superHonda123
12 Replies

2. Shell Programming and Scripting

Arithmetic calculation on real numbers in Bourne Shell Script

I am begining to learn bourne shell and as a practice I have written a script which when given the purchase price and percentage of discount calculates the savings. I somehow cannot figure out why my script fails to do arthimatic calculation on real numbers. Could anyone look at the script... (5 Replies)
Discussion started by: Tirmazi
5 Replies

3. Shell Programming and Scripting

calculation using awk or shell script in between the numbers

file A E969K D223L E400L E34L file B predicted 3 1 250 251 500 501 1000 The output should be E969K 501 1000 D223L 1 250 E400L 251 500 E34L 1 250 I tried in this way (1 Reply)
Discussion started by: cdfd123
1 Replies

4. Shell Programming and Scripting

KSH SHELL: problem calculation number of lines inside compressed file

Hi Gurus, I am working with a korn shell script to simplify some operations of calculation number of lines inside compressed file. The called function (inside a cycle) is the following: ######################################### # F.ne: CheckCount #########################################... (3 Replies)
Discussion started by: GERMANICO
3 Replies

5. Shell Programming and Scripting

Date calculation script

hello! I need a date calculation script that need to do that: ./date.sh 20090312 and the script need to give me which day is it for example monday friday or what else! can anyone help me?? its really urgent :S thx the help! (7 Replies)
Discussion started by: impish
7 Replies

6. Shell Programming and Scripting

time calculation in ksh script

I"m trying to calculate the duration of of backup within a ksh shell script but I get an error. #!/bin/ksh STTIM=`date '+%T'` EDTIM=`date '+%T'` .... .... echo "DURATION OF BACKUP: $((EDTIM - STTIM))" (5 Replies)
Discussion started by: Bperl1967
5 Replies

7. Shell Programming and Scripting

Math calculation over shell

Hi I am trying to calculate the rate at which something is happening. I have 2 files- a1 and b1. I want to calculate something like this ((wc -l a1)/(wc -l a1 + wc -l b1))*100 over a loop for different a and b. Is this possible, help me out fellas. Thanks a lot :) (5 Replies)
Discussion started by: jamie_123
5 Replies

8. Shell Programming and Scripting

Numeric calculation in shell scripting

Hi Team, how can i calculate the number as below in shell script for below expression. 34 /50 * 100 equals to 68% now how i would represent this in shell script. Thanks, Jewel (23 Replies)
Discussion started by: Jewel
23 Replies

9. Shell Programming and Scripting

How to do simple date (time) calculation in shell script?

Hi, I'm looking for a way to do a simple math calc during a shell script as a means of logging how long a particular task takes. For example... STARTTIME=whenever this script starts ./path/to/command.sh >>logfile.log TOTALTIME=<time at this stage of the script after above command... (7 Replies)
Discussion started by: nbsparks
7 Replies

10. Shell Programming and Scripting

Newbie question: modulo operator with negative operand, bug or feature?

Hi, I'm new to the Ash shell so my apologies if this is well known. In normal maths and other shells and languages I've used, the modulo operator always returns a positive remainder. For example see this discussion (first post so I can't hyperlink it): ... (11 Replies)
Discussion started by: FleetFoot
11 Replies
PARCHIVE(1)							   User Commands						       PARCHIVE(1)

NAME
parchive - RAID like data recovery for PAR ver 1.0 files DESCRIPTION
The idea behind the parchive is to provide a tool to apply the data-recovery capability concepts of RAID-like systems to the posting and recovery of multi-part archives on Usenet. Current filespec and clients support the volumes for 'X' parity volumes present. The key to this mission is a clean file format specification which provides all the necessary capabilities for programs to easily verify and regenerate single missing parts out of a set of archives. We might just be able to make binary posting and downloading on Usenet a little easier. That's a pretty cool goal! Note that parchive supports the old legacy version 1.0 PAR format. For new projects, use the par2 package which supports the version 2.0 PAR format which provides superior features. This manual page was written for the Debian GNU/Linux distribution because the original program does not have a manual page. USAGE
parchive c(heck) [options] <par file> Check parity archive parchive r(ecover) [options] <par file> Restore missing volumes parchive a(dd) [options] <par file> [files] Add files to parity archive parchive m(ix) [options] Try to restore from all parity files at once parchive i(nteractive) [<par files>] Interactive mode (very bare-bones) Options: (Can be turned off with '+') -m Move existing files out of the way -f Fix faulty filenames -p<n> Number of files per parity volume -n<n> Number of parity volumes to create -d Search for duplicate files -k Keep broken files -s Be smart if filenames are consistently different. +i Do not add following files to parity volumes +c Do not create parity volumes +C Ignore case in filename comparisons +H Do not check control hashes -v,+v Increase or decrease verbosity -h,-? Display this help -- Always treat following arguments as files SEE ALSO
The full documentation (such as it is) for parchive is maintained on the web site at <http://sourceforge.net/docman/dis- play_doc.php?docid=7717&group_id=30568> AUTHOR
This manual page was written by Rene Weber <rene_debmaint@elvenlord.com>, and edited by Vince Mulhollon <vlm@debian.org>, for the Debian GNU/Linux system (but may be used by others). parchive 1.1 May 30 2004 PARCHIVE(1)
All times are GMT -4. The time now is 12:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy