Here's a quick bash-only version for positive numbers. The trick is reading the values in. Once you do that the rest is straightforward.
I can see what you are doing, but forgive my ignorance; apart from the obvious bashisms, how do I use 'read' to input values directly from command line arguments without disk thrashing in POSIX 'dash'?
Everything MUST centre around 'dash' or POSIX 'sh'.
As for 'zsh', I can't be responsible for a non POSIX compliant shell.
This is the whole point of this [futile] exercise to see what is possible and what better than Fixed Point Arithmetic.
And I already assume a "fractional" part of 1000000000 and use "%.9f" to add any zeros to the end.
Anyhow I will try out your "MINUS" modification tomorrow.
Multiplication and division are harder still in 'dash'.
I'm sure DASH can divide and multiply absolutely fine. It has * and /.
Quote:
And I already assume a "fractional" part of 1000000000 and use "%.9f" to add any zeros to the end.
I noticed, but the way you're doing it is perhaps the hardest possible way. If you just keep your number as an integer, you can calculate it as an integer, because it is an integer. Addition and subtraction work completely straight. Multiplication and division will need correction before and afterwards respectively. And you will have to stay away from the integer limit because the result of multiplying 64-bit MAXINT by 64-bit MAXINT is a 128-bit number.
Anyway, you can use a here-document to feed values into read. There's another, older trick though, which works especially well in functions and should work anywhere.
Last edited by Corona688; 11-07-2018 at 11:58 AM..
Anyway, you can use a here-document to feed values into read.
WOW! I didn't find anything about this on the mighty WWW. This earns you a big thank you and certainly does open up new avenues...
Results on my usual gear:
Quote:
There's another, older trick though, which works especially well in functions and should work anywhere.
Now this I would be interested in, please post an example ASAP.
I will re-do my code accordingly and check against Python. Gimme a bit of time.
This is why I am an amateur and you are a professional, my knowledge is far less than yours and others in this sphere.
<thumb-up-smilie-here>
EDIT:
Done my own. ;o)
Bazza...
Last edited by wisecracker; 11-07-2018 at 06:56 PM..
Reason: Add my own text mode thumbs up...
has a permanent effect, so you often do
Sometimes you can use a sub shell:
read is a command, and you can set the environment just for the command
Unfortunately set is not a command. (You can call it a pseudo command or special command. The shell does not fork/exec like with a normal command, therefore IFS must be set beforehand.)
Last edited by MadeInGermany; 11-07-2018 at 07:24 PM..
This User Gave Thanks to MadeInGermany For This Post:
I was well aware of 'IFS' being permanent but the test code was proof of concept rather than a dedicated program.
If C688 had not mentioned the heredoc method then then I would not have known about it. My searching prowess must be poor using Google.
Having said that this is neat too, as it is also new to me:
So you get a thumbs up too:
Bazza.
Now this I would be interested in, please post an example ASAP.
I did? It is set -- arg1 arg2 arg3 ... which sets the $1 $2 $3 variables.
If you run it like set -- $variable it will split upon IFS, which is whatever you please, giving an easy way to split a string upon "." even in ancient shells which lack most modern string built-ins.
It works especially well in functions because otherwise you'd have to worry about overwriting the global $1 $2 etc, but inside a function you're only dealing with local ones, which will be gone soon anyway.
Beware that not only IFS is preserved -- every variable is preserved. Variable assignments inside the new shell don't copy into the old one. It's just like running commands behind a pipe.
Well, guys I saw a question about GOTO for Python.
So this gave me the inspiration to attempt a GOTO function for 'dash', (bash and ksh too).
Machine: MBP OSX 10.14.3, default bash terminal, calling '#!/usr/local/bin/dash'...
This is purely a fun project to see if it is possible in PURE... (3 Replies)
How to create a new mount point with 600GB and add 350 GBexisting mount point
Best if there step that i can follow or execute before i mount or add diskspace IN AIX
Thanks (2 Replies)
Hey all! :)
I'm trying to create a fixed mount point for an usb cardreader.
I've found a script on a raspberry pi forum which does the following:
usb stick is plugged in -> script checks the mount point for data -> script starts copying the files automatically -> script unmounts the... (0 Replies)
Discussion started by: Eomer
0 Replies
4. Post Here to Contact Site Administrators and Moderators
HI Everyone,
I have below source file
AAA|NAME1|ADDRESS1|300.20
BBB|NAME2|ADDRESS2|400.31
CCC|NAME3|ADDRESS3|300.34
I have requirement where I need to sum up fourth field in above fixed width pipe delimited flat file. When I use below code, it gives me value 1001.00
But I am expecting... (1 Reply)
hi,
I would like to ask or is it possible to dump a hex using dd from starting point to end point just like the "xxd -s 512 -l 512 <bin file>"
I know the redirect hexdump -C but i can't figure it out the combination options of dd.
Hope someone can share their knowledge..
Thanks in... (3 Replies)
Hi!
I'm new in these forums and more or less new with Unix. So... here is the question:
does anyone know where is redirected the output of a command when you put >&- after it?
Does it means any standard file descriptor?
Thanks! (2 Replies)
Anyone know of a guide or instructions for Solaris
I got to configure a SBUS HBA to talk to a tape robot.
I have done this on a switch but not point to point.
just going HBA >>>>> TAPE Fibre simple two nodes
Kie (6 Replies)