mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2021-10-04, 21:31   #23
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

3×372 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
Here is what you should test:

Code:
am=3
c4=2346021463111956
      echo "c4 is $c4 and am is $am"
      c4m=$(echo "expr($c4*$am)")
      echo "c4 is $c4 and c4m is $c4m"
      c4m=$(../../yafu/yafu $(expr $c4 \* $am) -silent)
      echo "c4 is $c4 and c4m is $c4m"
Note the spaces around the operator \* in expr; They are important delimiters. Also note that * has to be escaped with \, otherwise it will be wildcard for files in the current directory.
However, as proven in the supplied script, neither is necessary for the call to succeed:
Code:
../../yafu/yafu "expr($c*$m)" -silent
works just fine as long as I haven't opened a file, and spaces and \*, as well as original fail, if I have opened a file. BTW, spaces are accepted by YAFU, but "\*" is not.
EdH is offline   Reply With Quote
Old 2021-10-04, 21:37   #24
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

2×7×281 Posts
Default

Quote:
Originally Posted by EdH View Post
However, as proven in the supplied script, neither is necessary for the call to succeed:
Code:
../../yafu/yafu "expr($c*$m)" -silent
works just fine as long as I haven't opened a file, and spaces and \*, as well as original fail, if I have opened a file. BTW, spaces are accepted by YAFU, but "\*" is not.
I have
Code:
c4m=$(../../yafu/yafu $(expr $c4 \* $am) -silent)
You have
Code:
cm4=$(../../yafu/yafu "expr($c*$m)" -silent)
Do you see my extra $ for expr?

Last fiddled with by paulunderwood on 2021-10-04 at 21:49
paulunderwood is offline   Reply With Quote
Old 2021-10-04, 21:50   #25
kruoli
 
kruoli's Avatar
 
"Oliver"
Sep 2017
Porta Westfalica, DE

76610 Posts
Default

Wait, that's doing two fully different things!

There is expr of GNU coreutils (as in $(expr 2 \* 2)) and there is the YAFU function expr (as in expr(2*2) or ./yafu "expr(2*2)").

Edit: Executing something like ./yafu $(expr $var1 \* $var2) is like executing ./yafu 15, e.g. calling yafu only with a constant. GNU expr is already evaluating, so var1=$(var2 \* var3) or var1=$((var1*var2)) should be sufficient. I'm not sure up to which limit the latter one works.

Last fiddled with by kruoli on 2021-10-04 at 21:56 Reason: Additions.
kruoli is offline   Reply With Quote
Old 2021-10-04, 21:53   #26
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

2×7×281 Posts
Default

Quote:
Originally Posted by kruoli View Post
Wait, that's doing two fully different things!

There is expr of GNU coreutils (as in $(expr 2 \* 2)) and there is the YAFU function expr (as in expr(2*2) or ./yafu "expr(2*2)").
I'm not familiar with yafu. Shoud the quotes be escaped for yafu's expr in a bash expression?

Last fiddled with by paulunderwood on 2021-10-04 at 21:56
paulunderwood is offline   Reply With Quote
Old 2021-10-04, 21:55   #27
kruoli
 
kruoli's Avatar
 
"Oliver"
Sep 2017
Porta Westfalica, DE

2·383 Posts
Default

Basically, the specific problem was that the command line was ignored by YAFU in the script because of redirecting a file. The syntax was okay in all cases.

Last fiddled with by kruoli on 2021-10-04 at 21:56 Reason: Clarifications.
kruoli is offline   Reply With Quote
Old 2021-10-04, 21:59   #28
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

100B16 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
I'm not familiar with yafu. Shoud the quotes be escaped for yafu's expr in a bash line?
YAFU expects
Code:
./yafu "expr(number*number)" <options>
for its "expr()" call. The quotes tell YAFU the function (in this case expr) to invoke. Then the <options> are added outside the quotes.
EdH is offline   Reply With Quote
Old 2021-10-04, 22:02   #29
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

2×7×281 Posts
Default

Quote:
Originally Posted by EdH View Post
YAFU expects
Code:
./yafu "expr(number*number)" <options>
for its "expr()" call. The quotes tell YAFU the function (in this case expr) to invoke. Then the <options> are added outside the quotes.
And what happens with:

Code:
cm4=$(../../yafu/yafu \"expr($c*$m)\" -silent)
?
paulunderwood is offline   Reply With Quote
Old 2021-10-04, 22:15   #30
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

100B16 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
And what happens with:

Code:
cm4=$(../../yafu/yafu \"expr($c*$m)\" -silent)
?
Without file read:
Code:
YAFU says 31363920*3 is ytestW-N.sh: command substitution: line 15: syntax error near unexpected token `('
ytestW-N.sh: command substitution: line 15: `../../yafu/yafu \"expr($c*$m)\" -silent)'
With file read:
Code:
YAFU says 31363920*3 is ytestW-N.sh: command substitution: line 15: syntax error near unexpected token `('
ytestW-N.sh: command substitution: line 15: `../../yafu/yafu \"expr($c*$m)\" -silent)'

no variable indicator (@): interpreting batchfile lines as input expressions
 eof; done processing batchfile

Edit 2: These are the lines as edited into the above script:
Code:
cm4=$(../../yafu/yafu \"expr($c*$m)\" -silent)
echo $cm4

Last fiddled with by EdH on 2021-10-04 at 22:21 Reason: Removed irrelevant portion of first code block.
EdH is offline   Reply With Quote
Old 2021-10-04, 22:21   #31
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

2·7·281 Posts
Default

One last thing to try:

Code:
cm4=$(../../yafu/yafu \"expr($c\*$m)\" -silent)
Then I'll d/l YAFU
paulunderwood is offline   Reply With Quote
Old 2021-10-04, 22:27   #32
EdH
 
EdH's Avatar
 
"Ed Hall"
Dec 2009
Adirondack Mtns

10000000010112 Posts
Default

Quote:
Originally Posted by paulunderwood View Post
One last thing to try:

Code:
cm4=$(../../yafu/yafu \"expr($c\*$m)\" -silent)
Then I'll d/l YAFU
Code:
YAFU says 31363920*3 is ytestW-N.sh: command substitution: line 15: syntax error near unexpected token `('
ytestW-N.sh: command substitution: line 15: `../../yafu/yafu \"expr($c\*$m)\" -silent)'
You would have to build YAFU, which would take a little bit. Unless you'd really like to pursue this, I'm OK with my current work around, which parses out the wanted result, from all the extra.
EdH is offline   Reply With Quote
Old 2021-10-05, 01:45   #33
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

393410 Posts
Default

Code:
#!/bin/bash

a="31363920 948583258055568 -21094061301960794201597 -101781123694367174730692456309 1859252514529139843616145918243322920 1347307311985305327578340438707291179185984 951738172269489471300643 -167704995415343890580296180142353038"
echo "$a" > testcase
#exec < "testcase"
read b < testcase 
c="31363920"
d="${a:0:8}"
e="${b:0:8}"
m="3"

echo "m is $m and d is $d and c is $c and b is ${b:0:10}... and a is ${a:0:10}..."
printf "\nYAFU says $c*$m is "
../yafu/yafu "expr($c*$m)" -silent
printf "\nYAFU says $d*$m is "
../yafu/yafu "expr($d*$m)" -silent
printf "\nYAFU says $e*$m is "
../yafu/yafu "expr($e*$m)" -silent
results in:

Code:
m is 3 and d is 31363920 and c is 31363920 and b is 31363920 9... and a is 31363920 9...

YAFU says 31363920*3 is 94091760

YAFU says 31363920*3 is 94091760

YAFU says 31363920*3 is 94091760
Idea lifted from https://linuxhint.com/read_file_line_by_line_bash/

(I compiled msieve for YAFU without zlib.)
paulunderwood is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Startup Script Gerard Information & Answers 2 2018-11-01 08:40
Simple Script to get Trial Factoring Work jfamestad PrimeNet 3 2016-11-06 20:32
bash script for extracting primenet-status gLauss Linux 0 2010-07-31 11:19
Could you help me change this into a bash script? jasong Programming 1 2007-11-29 05:59
Help with Startup Script Proggie Software 1 2004-12-19 11:54

All times are UTC. The time now is 10:05.


Wed Dec 1 10:05:05 UTC 2021 up 131 days, 4:34, 1 user, load averages: 1.61, 1.60, 1.36

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.