03-21-2011
Could be written (with arithmetic evaluation and array)
bash code:
#!/usr/bin/bash
parity=(even odd) # parity[0]='even' parity[1]='odd'
read -p "enter a number: " a
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
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
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
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
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
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
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
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
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
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
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
od(1) General Commands Manual od(1)
Name
od - create file octal dump
Syntax
od [options] [file] [offset] [label]
Description
The command displays file, or its standard input, in one or more dump formats as selected by the first argument. If the first argument is
missing, -o is the default. Dumping continues until end-of-file.
Options
-a[p|P] Interprets bytes as characters and display them with their ACSII names. If the p character is given also, then bytes with even
parity are underlined. The P character causes bytes with odd parity to be underlined. Otherwise the parity bit is ignored.
-b Displays bytes as unsigned octal.
-c Displays bytes as ASCII characters. Certain non-graphic characters appear as C escapes: null= , backspace=, formfeed=f, new-
line=
, return=
, tab= ; others appear as 3-digit octal numbers. Bytes with the parity bit set are displayed in octal.
-d Displays short words as unsigned decimal.
-f Displays long words as floating point.
-h Displays short words as unsigned hexadecimal.
-i Displays short words as signed decimal.
-l Displays long words as signed decimal.
-o Displays short words as unsigned octal.
-s[n] Looks for strings of ASCII characters of n minimum length. By default, the minimum length is 3 characters.
-v Displays all data and indicates lines identical to the last line shown with an * in column 1.
-w[n] Specifies the number of input bytes to be interpreted and displayed on each output line. If w is not specified, 16 bytes are read
for each display line. If n is not specified, it defaults to 32.
-x Displays short words as hexadecimal.
An upper case format character implies the long or double precision form of the object.
The offset argument specifies the byte offset into the file where dumping is to commence. By default this argument is interpreted in
octal. A different radix can be specified; If ``.'' is appended to the argument, then offset is interpreted in decimal. If offset begins
with ``x'' or ``0x'', it is interpreted in hexadecimal. If ``b'' (``B'') is appended, the offset is interpreted as a block count, where a
block is 512 (1024) bytes. If the file argument is omitted, an offset argument must be preceded by ``+''.
The radix of the displayed address is the same as the radix of the offset, if specified; otherwise it is octal.
The label is interpreted as a pseudo-address for the first byte displayed. It is shown in ``()'' following the file offset. It is
intended to be used with core images to indicate the real memory address. The syntax for label is identical to that for offset.
Restrictions
A file name argument can't start with ``+''. A hexadecimal offset can't be a block count. Only one file name argument can be given.
It is an historical botch to require specification of object, radix, and sign representation in a single character argument.
See Also
adb(1) - VAX only, dbx(1)
od(1)