LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-20-2007, 12:29 PM   #1
mystical dervish
LQ Newbie
 
Registered: May 2007
Posts: 25

Rep: Reputation: 15
arithmethic function inside shell script


I want to evaluate an arithmetic expression, where it's a line of shell script, how can I calculate this expression containig log function

tdf= tf*log(n/F) // this is my expression
I know that shell doesnt support these funcs, but is there a service could be embedded in shell to do that ?? where those variables (n, F, ...) are shell vars
can some one help
 
Old 08-20-2007, 01:00 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
A method could be using gawk, as in
Code:
n=1
F=10
tf=12
tdf=$(echo "$n $F $tf" | gawk '{print $3*log($1/$2)}')
 
Old 08-20-2007, 01:35 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Another alternative would be bc



Cheers,
Tink
 
Old 08-21-2007, 04:57 AM   #4
mystical dervish
LQ Newbie
 
Registered: May 2007
Posts: 25

Original Poster
Rep: Reputation: 15
thank you it does work
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 12:21 PM
where to place certiain commands inside shell script beeblequix Linux - Newbie 8 08-10-2006 11:12 AM
Can I execute a shell script from inside a php one. prabhatsoni Linux - Software 2 05-24-2006 05:40 AM
embedded shell script from inside fortran TheBrick Programming 2 05-22-2006 08:23 AM
changing the user inside a shell script sanjith11 Programming 2 04-22-2004 07:44 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration