LinuxQuestions.org
Help answer threads with 0 replies.
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 09-08-2015, 11:21 PM   #1
Blue-Knight
LQ Newbie
 
Registered: Jan 2014
Distribution: LinuxMint
Posts: 11

Rep: Reputation: Disabled
Calc - Help to get rid of undesired character


Hi!

I have a code:
Code:
part1=10; for (( c=1; c<=12; c++ )); do part2=$(calc -p "$part1 / 100 * 25"); part1=$(calc -p "$part1 + $part2"); echo "$part1"; done
I have this problem:
Code:
12.5
15.625
19.53125
24.4140625
30.517578125
38.14697265625
47.6837158203125
59.604644775390625
74.50580596923828125
93.1322574615478515625
69.84919309616088867188
87.31149137020111083985
The problem is that for "calc", this "93.13 + ~23.12" and this "93.13 + 23.12" is not the same and the result is "incorrect".

Is there any way I could get rid of that annoying behavior?

Thank you!

EDIT:
I found a "solution" by doing this:
Code:
part1=10; for (( c=1; c<=12; c++ )); do part2=$(calc -p "$part1 / 100 * 25" | tr -d '~'); part1=$(calc -p "$part1 + $part2" | tr -d '~'); echo "$part1"; done
If you know of a better solution, please let me know.

Thank you!

EDIT:
A better solution was provided by norobro:
Code:
part1=10; for (( c=1; c<=12; c++ )); do part2=$(calc -p -d "$part1 / 100 * 25"); part1=$(calc -p -d "$part1 + $part2"); echo "$part1"; done
Thank you!

Last edited by Blue-Knight; 09-09-2015 at 10:38 AM.
 
Old 09-09-2015, 10:16 AM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
From the calc man page:
Quote:
-d Disable the printing of the opening title.
 
1 members found this post helpful.
Old 09-09-2015, 10:34 AM   #3
Blue-Knight
LQ Newbie
 
Registered: Jan 2014
Distribution: LinuxMint
Posts: 11

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by norobro View Post
From the calc man page:
Well, that is not clear. But it worked.

Thank you!
 
Old 09-09-2015, 10:49 AM   #4
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
You're welcome!

Quote:
Originally Posted by Blue-Knight View Post
Well, that is not clear.
What do you find not clear about it?

Edit: I see what you mean, the "title" in post #2 is a typo. I read the source code and copied from the man page. I reported it to the devs.
From lib_calc.c:
Code:
	/*
	 * -d turns off resource_debug and tilde
	 */

Last edited by norobro; 09-10-2015 at 04:01 PM.
 
  


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
prevent notification about undesired update d3249 Debian 3 12-18-2010 04:51 PM
xargs undesired behaviour. stf92 Linux - Software 6 08-06-2010 05:23 AM
Simple Script-Undesired out??? shalomajay Programming 1 03-09-2006 06:30 PM
IPTables Undesired NATing Wraezor Linux - Security 3 07-15-2005 05:09 AM
can't get rid of "q" character popping up cmacklin Linux - Newbie 0 10-29-2004 11:50 PM

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

All times are GMT -5. The time now is 03:18 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