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
gettytab(5)							File Formats Manual						       gettytab(5)

Name
       gettytab - terminal configuration data base

Syntax
       /etc/gettytab

Description
       The  file  is  a simplified version of the data base used to describe terminal lines.  The initial terminal login process accesses the file
       each time it starts, allowing simpler reconfiguration of terminal characteristics.  Each entry in the data base is  used  to  describe  one
       class of terminal.

       There is a default terminal class, default, that is used to set global defaults for all other classes.  That is, the default entry is read,
       and then the entry for the class required is used to override particular settings.

Capabilities
       Refer to for a description of the file layout.  The default column below lists defaults	obtained  if  there  is  no  entry  in	the  table
       obtained, nor one in the special default table.

       -------------------------------------------------------------------
       Name   Type   Default	  Description
       -------------------------------------------------------------------
       ab     bool   false	  Auto-baud speed selection mechanism
       ap     bool   false	  Terminal uses any parity
       bd     num    0		  Backspace delay
       bk     str    0377	  Alternate  end of line character (input
				  break)
       cb     bool   false	  Use crt backspace mode
       cd     num    0		  Carriage-return delay
       ce     bool   false	  Use crt erase algorithm
       ck     bool   false	  Use crt kill algorithm
       cl     str    NULL	  Screen clear sequence
       co     bool   false	  Console - add 
 after login prompt
       ds     str    ^Y 	  Delayed suspend character
       ec     bool   false	  Leave echo 2OFF
       ep     bool   false	  Terminal uses even parity
       er     str    ^? 	  Erase character
       et     str    ^D 	  End of text 2EOF character
       ev     str    NULL	  Initial environment
       f0     num    unused	  Tty mode flags to write messages
       f1     num    unused	  Tty mode flags to read login name
       f2     num    unused	  Tty mode flags to leave terminal as
       fd     num    0		  Form-feed (vertical motion) delay
       fl     str    ^O 	  Output flush character
       hc     bool   false	  Do not hangup line on last close
       he     str    NULL	  Hostname editing string
       hn     str    hostname	  Hostname
       ht     bool   false	  Terminal has real tabs
       ig     bool   false	  Ignore garbage characters in login name
       im     str    NULL	  Initial (banner) message
       in     str    ^C 	  Interrupt character
       is     num    unused	  Input speed
       kl     str    ^U 	  Kill character
       lc     bool   false	  Terminal has lower case
       lm     str    login:	  Login prompt
       ln     str    ^V 	  ``literal next'' character
       lo     str    /bin/login   Program to exec when name obtained
       nd     num    0		  Newline (line-feed) delay
       nl     bool   false	  Terminal has (or might have) a  newline
				  character
       nx     str    default	  Next table (for auto speed selection)
       op     bool   false	  Terminal uses odd parity

       os     num    unused	  Output speed
       p8     bool   false	  Use 8-bit characters
       pc     str     	  Pad character
       pd     bool   false	  Disable parity on output
       pe     bool   false	  Use printer (hard copy) erase algorithm
       pf     num    0		  Delay  between first prompt and follow-
				  ing flush (seconds)
       ps     bool   false	  Line connected to a MICOM port selector
       qu     str    ^ 	  Quit character
       rp     str    ^R 	  Line retype character
       rw     bool   false	  Do not use raw for input, use cbreak
       sp     num    unused	  Line speed (input and output)
       su     str    ^Z 	  Suspend character
       tc     str    none	  Table continuation
       to     num    0		  Timeout (seconds)
       tt     str    NULL	  Terminal type (for environment)
       ub     bool   false	  Do unbuffered output (of prompts and so
				  forth)
       uc     bool   false	  Terminal is known upper-case only
       we     str    ^W 	  Word erase character
       xc     bool   false	  Do not echo control chars as ^X
       xf     str    ^S 	  XOFF (stop output) character
       xn     str    ^Q 	  XON (start output) character
       -------------------------------------------------------------------

       If  no  line  speed  is specified, speed will not be altered from that which prevails when is entered.  Specifying an input or output speed
       will override line speed for stated direction only.

       Terminal modes to be used for the output of the message, for input of the login name, and to leave the terminal set as upon completion, are
       derived	from  the  Boolean flags specified.  If the derivation should prove inadequate, any (or all) of these three may be overridden with
       one of the or numeric specifications, which can be used to specify (usually in octal, with a leading 0) the  exact  values  of  the  flags.
       Local (new tty) flags are set in the top 16 bits of this (32-bit) value.

       Should  receive	a  null character (presumed to indicate a line break), it will restart using the table indicated by the entry. If there is
       none, it will reuse its original table.

       Delays are specified in milliseconds; the nearest possible delay available in the tty driver will be used.   Should  greater  certainty	be
       desired, delays with values 0, 1, 2, and 3 are interpreted as choosing that particular delay algorithm from the driver.

       The screen clear string may be preceded by a (decimal) number of milliseconds of delay required (a la termcap).	This delay is simulated by
       repeated use of the pad character

       The initial message, and login message, and may include the character sequence to obtain the host name, to obtain the terminal name, and to
       obtain  the  date.  (%% obtains a single percent (%) character.)  The host name is normally obtained from the system, but may be set by the
       table entry.  In either case, it can be edited with The string is a sequence of characters; each character that is neither an at  sign  (@)
       nor  a number sign (#) is copied into the final host name.  An at sign (@) in the string causes one character from the real host name to be
       copied to the final host name.  A number sign (#) in the string causes the next character of the real host name to be skipped.  Surplus	at
       signs (@) and number signs (#) are ignored.

       When  executes  the login process, given in the string (usually it will have set the environment to include the terminal type, as indicated
       by the string, if it exists.  The string can be used to enter additional data into the  environment.   It  is  a  list  of  comma-separated
       strings, each of which should be of the form name=value.

       If  a  nonzero  timeout	is  specified  with then will exit within the indicated number of seconds, either having received a login name and
       passed control to or having received an alarm signal, and exited.  This may be useful to hang up dial-in lines.

       The flag allows use of 8-bit characters.

       The flag turns off parity on output.  Output from is even parity unless the flag, the flag, or the flag is specified.  The flag is used	to
       allow  any parity on input.  The flag may be specified with the flag to allow any parity on input, but generate odd(even) parity on output.
       The parity on output is accomplished by using the eighth bit as the parity bit.	does not check parity of input characters in RAW  mode	or
       8-bit mode.

       Terminals  that	are set up to operate in 8-bit mode should use entries which include the flag.	If a terminal that is set up in 8-bit mode
       fails to use an appropriate entry, the output from and can appear as multinational characters.  This is due  to	the  fact  that  uses  the
       eighth bit of characters to provide software generated parity.  The software parity generation will transform certain ASCII characters into
       multinational characters.  Earlier releases of the ULTRIX operating system did not display these multinational characters, due to the  lack
       of full 8-bit support in the terminal subsystem.

Restrictions
       Because	some users insist on changing their default special characters, it is wise to define at least the erase, kill, and interrupt char-
       acters in the default table.  In all cases, # or CTRL/H typed in a login name will be treated as an erase character, and @ will be  treated
       as a kill character.

       destroys the environment, so there is no point setting it in

See Also
       termcap(5), getty(8)

																       gettytab(5)
All times are GMT -4. The time now is 03:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy