Bash squares and exponents


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash squares and exponents
# 1  
Old 06-11-2008
Bash squares and exponents

I'm trying to write a simple bash script and I need something like
var=2^(5+i)
where i is another variable. How would do I this in bash?
# 2  
Old 06-11-2008
bash v 2.02 & up has the ** operator which is exponentiation
Code:
i=2
var=2**(5+$i)

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

Different behavior between bash shell and bash script for cmd

So I'm trying to pass certain json elements as env vars and use them later on in a script. Sample json: JSON='{ "Element1": "file-123456", "Element2": "Name, of, company written in, a very weird way", "Element3": "path/to/some/file.txt", }' (part of the) script: for s... (5 Replies)
Discussion started by: da1
5 Replies

3. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

4. Shell Programming and Scripting

Bash to select text and apply it to a selected file in bash

In the bash below I am asking the user for a panel and reading that into bed. Then asking the user for a file and reading that into file1.Is the grep in bold the correct way to apply the selected panel to the file? I am getting a syntax error. Thank you :) ... (4 Replies)
Discussion started by: cmccabe
4 Replies

5. Shell Programming and Scripting

Squares in saved code

can you help i am merging 2 files together and saving to a third file with awk and its working with this code awk 'OFS="";NR==FNR{a=$0;next} {print a,"\n","\b",$0}' file1 file2 > file3the problem is in file3 when its saved i get a small square at the start of every 2nd line (see picture) ... (6 Replies)
Discussion started by: bob123
6 Replies

6. Shell Programming and Scripting

Squares on a chessboard calculation

Hi All, Just curious if the following formula is possible within a shell script: n x (n + 1) x (2n + 1) ______________________ 6 so far im just using a simple expression but need to implement the above. Many thanks in advance #!/bin/sh echo "\n" echo -------- Squares... (5 Replies)
Discussion started by: sammclean23
5 Replies

7. UNIX for Dummies Questions & Answers

Exponents

Hi! I have a set of numbers like this 1192.0 0.219E+00 1192.0 -0.446E-02 1192.0 0.924E-01 1192.0 -0.306E-01 1192.0 0.105E-03 1192.0 0.819E-01 Is there an easy way (with awk maybe?) to make all numbers in the second column have the same exponent. Thanks! (1 Reply)
Discussion started by: cosmologist
1 Replies

8. UNIX and Linux Applications

Grep Exponents

I cannot figure out how to grep for an exponent in a file. Any help is greatly appreciated. (1 Reply)
Discussion started by: onshore
1 Replies

9. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies
Login or Register to Ask a Question