Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Working out percentage in shell script Post 302990627 by RudiC on Sunday 29th of January 2017 02:58:43 PM
Old 01-29-2017
Round it up? Means WHAT? How about scale=2?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script 'system' linking to local shell script not working

Trying to figure out why this works: printpwd.pl #!/usr/bin/perl use CGI::Carp qw( fatalsToBrowser ); print "Content-type: text/html\n\n"; $A = system("pwd"); $A = `pwd`; print "$A\n"; ^^actually that works/breaks if that makes any sense.. i get the working directory twice but when... (5 Replies)
Discussion started by: phpfreak
5 Replies

2. UNIX for Dummies Questions & Answers

Working out the percentage between two values

Hi there, I am totally new to Unix, I am trying to work out the percentage between two values in a ksh shell script and assign the result to a variable. Value1=577 Values2=244 So the calculation would be as follows: ((Value1 - Value2) / Value1) * 100 How would I be able to achieve... (2 Replies)
Discussion started by: NextLevelAndi
2 Replies

3. Shell Programming and Scripting

Script shell, how to calculate percentage?

hello, please can you help me. jj and kk are two numbers which are the result of an sql program. I would like to calculate the ratio jj/kk*100. I have done this: ratio=$((jj/kk * 100)) or ratio=`expr $jj \/ expr $kk) but the result is 0 What can i do? Thanks for help. (3 Replies)
Discussion started by: likeaix
3 Replies

4. Programming

Shell script to find Percentage?

Hi all, I havea log of data.log bear,10000,white bear,5000,black chicken,2000,white chicken,4000,yellow chicken,3000,black lion,6000,yellow lion,1000,white How can we have shell script to get the percentage of each animals? Thanks. (8 Replies)
Discussion started by: sabercats
8 Replies

5. Shell Programming and Scripting

expect script inside shell script not working.

Shell Scipt: temp.sh su - <$username> expect pass.exp Expect script: pass.exp #!/usr/bin/expect -f # Login ####################### expect "Password: " send "<$password>\r" it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Discussion started by: bhavesh.sapra
2 Replies

6. UNIX for Dummies Questions & Answers

Percentage / Multiplication in Shell Script

Hello, I am trying to compute the percentage in a script as shown below: PerCover=`echo "scale=2 ; 100 \* ($InputCover/$Total)" | bc` However the PerCover value is blank/null. What do I need to do differently? Thanks for your input! ~Guss (1 Reply)
Discussion started by: Gussifinknottle
1 Replies

7. Shell Programming and Scripting

Shell script not working

. /home/bscs6/.kshrc set -x monthy=`date +%m` daty=`date +%d` yeary=`date +%Y` cd /home/bscs6/scripts sqlplus sysadm/sysadm@SEGODI @lms_profile.sql mv /home/bscs6/scripts/lmsprofile.log /home/bscs6/scripts/LMS_PROFILE_DUMP_$daty$monthy$yeary.txt gives me the error below: LMS_PROFILE.sh:... (3 Replies)
Discussion started by: malefho
3 Replies

8. Shell Programming and Scripting

Cp not working in shell script but running perfectly from shell

Dear All, I have script. Dest="" IFS=' ' for translation in $(echo $MY_MAP) do t1=$(echo $translation | cut -d"=" -f1) t2=$(echo $translation | cut -d"=" -f2| cut -d"," -f1) if then Dest=$UNX/$u_product_path/$u_study_path/$UNXTR/$t2 break; ... (4 Replies)
Discussion started by: yadavricky
4 Replies

9. Shell Programming and Scripting

Working out percentage of memory utilization

Hi there I am middle of writing a script to allow me to see the % of the memory which is being used. When I submit my script I don't get any errors but I just get a blank output. Any pointers? available=`free -m | grep available` if then ... (7 Replies)
Discussion started by: simpsa27
7 Replies

10. HP-UX

Shell /awk script for Percentage

having two columns, A and B.. i need to add another column C in a file and calculate the percentage based on the column A and B. (COLUMN B/ COLUMN A *100) . "|" is delimiter separating the A and B.. need C column with the percentage value. Thanks for your help 100|50 |50% ... (6 Replies)
Discussion started by: kartikirans
6 Replies
bc(1)								   User Commands							     bc(1)

NAME
bc - arbitrary precision arithmetic language SYNOPSIS
/usr/bin/bc [-c] [-l] [file]... /usr/xpg6/bin/bc [-c] [-l] [file]... DESCRIPTION
The bc utility implements an arbitrary precision calculator. It takes input from any files given, then reads from the standard input. If the standard input and standard output to bc are attached to a terminal, the invocation of bc is interactive, causing behavioral con- straints described in the following sections. bc processes a language that resembles C and is a preprocessor for the desk calculator pro- gram dc, which it invokes automatically unless the -c option is specified. In this case the dc input is sent to the standard output instead. USAGE
The syntax for bc programs is as follows: L Means a letter a-z, E Means an expression: a (mathematical or logical) value, an operand that takes a value, or a combination of operands and operators that evaluates to a value, S Means a statement. Comments Enclosed in /* and */. Names (Operands) Simple variables: L. Array elements: L [ E ] (up to BC_DIM_MAX dimensions). The words ibase, obase (limited to BC_BASE_MAX), and scale (limited to BC_SCALE_MAX). Other Operands Arbitrarily long numbers with optional sign and decimal point. Strings of fewer than BC_STRING_MAX characters, between double quotes ("). ( E ) sqrt ( E ) Square root length ( E ) Number of significant decimal digits. scale ( E ) Number of digits right of decimal point. L ( E , ... , E ) Operators + - * / % ^ (% is remainder; ^ is power) ++ -- (prefix and postfix; apply to names) == <= >= != < > = =+ =- =* =/ =% =^ Statements E { S ;... ; S } if ( E ) S while ( E ) S for ( E ; E ; E ) S null statement break quit .string Function Definitions define L ( L ,..., L ) { auto L ,..., L S ;... S return ( E ) } Functions in -l Math Library s(x) sine c(x) cosine e(x) exponential l(x) log a(x) arctangent j(n,x) Bessel function All function arguments are passed by value. The value of a statement that is an expression is printed unless the main operator is an assignment. Either semicolons or new-lines may separate statements. Assignment to scale influences the number of digits to be retained on arithmetic operations in the manner of dc. Assignments to ibase or obase set the input and output number radix respectively. The same letter may be used as an array, a function, and a simple variable simultaneously. All variables are global to the program. auto variables are stacked during function calls. When using arrays as function arguments or defining them as automatic variables, empty square brackets must follow the array name. OPTIONS
The following operands are supported: -c Compiles only. The output is dc commands that are sent to the standard output. /usr/bin/bc -l Defines the math functions and initializes scale to 20, instead of the default zero. /usr/xpg6/bin/bc -l Defines the math functions and initializes scale to 20, instead of the default zero. All math results have the scale of 20. OPERANDS
The following operands are supported: file A pathname of a text file containing bc program statements. After all cases of file have been read, bc reads the standard input. EXAMPLES
Example 1 Setting the precision of a variable In the shell, the following assigns an approximation of the first ten digits of n to the variable x: x=$(printf "%s " 'scale = 10; 104348/33215' | bc) Example 2 Defining a computing function Defines a function to compute an approximate value of the exponential function: scale = 20 define e(x){ auto a, b, c, i, s a = 1 b = 1 s = 1 for(i=1; 1==1; i++){ a = a*x b = b*i c = a/b if(c == 0) return(s) s = s+c } } Example 3 Printing the approximate values of the function Prints approximate values of the exponential function of the first ten integers: for(i=1; i<=10; i++) e(i) or for (i = 1; i <= 10; ++i) { e(i) } ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of bc: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. EXIT STATUS
The following exit values are returned: 0 All input files were processed successfully. unspecified An error occurred. FILES
/usr/lib/lib.b mathematical library /usr/include/limits.h to define BC_ parameters ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWesu | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
dc(1), awk(1), attributes(5), environ(5), standards(5) NOTES
The bc command does not recognize the logical operators && and ||. The for statement must have all three expressions (E's). SunOS 5.11 29 Aug 2003 bc(1)
All times are GMT -4. The time now is 03:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy