![]() |
![]() |
#1 |
"Ed Hall"
Dec 2009
Adirondack Mtns
7·751 Posts |
![]()
I have the following in a BASH script:
Code:
echo "c4 is $c4 and am is $am" c4m=$(../../yafu/yafu "expr($c4*$am)" -silent) echo "c4 is $c4 and c4m is $c4m" Code:
c4 is -2293531595601876 and am is 3 c4 is -2293531595601876 and c4m is no variable indicator (@): interpreting batchfile lines as input expressions eof; done processing batchfile Code:
#!/bin/bash c4=-2293531595601876 am=3 echo "c4 is $c4 and am is $am" c4m=$(../../yafu/yafu "expr($c4*$am)" -silent) echo "c4 is $c4 and c4m is $c4m" Code:
c4 is -2293531595601876 and am is 3 c4 is -2293531595601876 and c4m is -6880594786805628 * I have tried these lines in two functions and in various locations in the main body of the larger script with no success. The scripts are located in the same directory. All thoughts welcome. . . |
![]() |
![]() |
![]() |
#2 | |
(loop (#_fork))
Feb 2006
Cambridge, England
144668 Posts |
![]() Quote:
What happens if you replace the '$(../../yafu/yafu' with '$(echo' ? That error message is coming from yafu not from bash (that is, yafu's output is that error message and has been captured into $c4m), so it looks as if the thing going into yafu has been somehow garbled ... Last fiddled with by fivemack on 2021-10-02 at 19:02 |
|
![]() |
![]() |
![]() |
#3 | |
"Ed Hall"
Dec 2009
Adirondack Mtns
7·751 Posts |
![]() Quote:
Code:
c4 is 2346021463111956 and am is 3 c4 is 2346021463111956 and c4m is expr(2346021463111956*3) -silent c4 is 2346021463111956 and c4m is 7038064389335868 Code:
c4 is 2346021463111956 and am is 3 c4 is 2346021463111956 and c4m is expr(2346021463111956*3) -silent c4 is 2346021463111956 and c4m is no variable indicator (@): interpreting batchfile lines as input expressions eof; done processing batchfile Code:
am=3 echo "c4 is $c4 and am is $am" c4m=$(echo "expr($c4*$am)" -silent) echo "c4 is $c4 and c4m is $c4m" c4m=$(../../yafu/yafu "expr($c4*$am)" -silent) echo "c4 is $c4 and c4m is $c4m" I fully agree with your assessment. That's why I didn't consider it a YAFU issue. But, I can't figure out what's wrong with the calling script. I'm thinking of using a separate script file to work around this, instead of embedding it in the main script. Thanks! |
|
![]() |
![]() |
![]() |
#4 |
"Ed Hall"
Dec 2009
Adirondack Mtns
10100100010012 Posts |
![]()
I'm guessing it's my personal gremlin screwing with me. I wrote a separate script just to perform the task for my main program and it won't work, either. The only difference I can think of is the way the variables are assigned. In the working script, the variables are directly assigned their value. In the broken scripts, the value is acquired via parsing. The best I can come up ATM, is that there is some "invisible" artifact in the parsed values.
|
![]() |
![]() |
![]() |
#5 |
"Composite as Heck"
Oct 2017
3×311 Posts |
![]()
At first I thought you were using the expr utility and passing a number to yafu so noodled with that, but you're actually passing the string "expr(a*b)" to be evaluated by yafu (?) (sorry, unfamiliar with yafu). Either way you may need to delimit * so that it doesn't get substituted by the shell, and/or include spaces between the variables and the operator if yafu works like expr. Any difference in how you're calling the scripts that may let one substitute and the other not?
Code:
u20@u20:~/textdir$ jam="$(expr -2293531595601876 * 3)";echo $jam expr: syntax error: unexpected argument ‘file_in_cd’ u20@u20:~/textdir$ jam="$(expr -2293531595601876 \* 3)";echo $jam -6880594786805628 u20@u20:~/textdir$ jam="$(expr -2293531595601876\*3)";echo $jam -2293531595601876*3 |
![]() |
![]() |
![]() |
#6 |
"Ed Hall"
Dec 2009
Adirondack Mtns
7·751 Posts |
![]()
I've tried lots of variations including \*, but mostly, they don't work with YAFU.
I'm still confused as to what the difference may be between a specific variable initialization and the variable coming from an operation. The two variables "appear" identical, but don't work the same. Oddly, I have used this in the past and it worked fine there. I need to see if I can find any of those scripts and see if I can learn anything from them. |
![]() |
![]() |
![]() |
#7 |
Sep 2009
3·809 Posts |
![]()
What happens if you add set -x to the script? It should show you what the shell thinks the command it's executing is. Try it both in the small working script and the big one where it does not work. See the man page for bash for details (search for "SHELL BUILTIN COMMANDS" and scroll down).
|
![]() |
![]() |
![]() |
#8 | |
"Ed Hall"
Dec 2009
Adirondack Mtns
7·751 Posts |
![]() Quote:
For the time being, unless the above gets me some good info, I have come up with a solution in the following way: I know the following: Code:
"expr($test*$m)" | ../../yafu/yafu I will probably run with this solution for now, unless I can easily find why the earlier script versions don't work and correct it. |
|
![]() |
![]() |
![]() |
#9 | |
"Ed Hall"
Dec 2009
Adirondack Mtns
7×751 Posts |
![]() Quote:
Code:
+ ../../yafu/yafu 'expr(756756*3)' -silent 2270268 ... + ../../yafu/yafu 'expr(756756*3)' -silent no variable indicator (@): interpreting batchfile lines as input expressions eof; done processing batchfile |
|
![]() |
![]() |
![]() |
#10 |
Sep 2009
3·809 Posts |
![]()
My knowledge of shell scripting has nearly run out. But there must be *something* in the big script that is affecting yafu. Have you done anything with stdin or stdout in the big script? Try adding </dev/null to the yafu call. And look for anything else that could affect yafu. You could try cutting a copy of the big script down by deleting bits of it until yafu works (hopefully before it's the same as the small script!)
Sorry I've run out of ideas. |
![]() |
![]() |
![]() |
#11 |
"Oliver"
Sep 2017
Porta Westfalica, DE
22×32×37 Posts |
![]()
Have a look at line 855 of driver.c, it says if (isatty(fileno(stdin)) == 0) (in my current GIT checkout), and this is the only point where is_cmdline_run gets set to 2 and 2 is the only value which leads to yafu_obj.USEBATCHFILE being set to 2 (also the only occurence), the other possible value for yafu_obj.USEBATCHFILE would be 1, but we can assume that it is not 1, because you have not set the batchfile option. So we enter the if in line 230, which is the only place where prepare_batchfile gets called, and this is the only place where the message "no variable indicator (@) ..." gets printed.
If I am correct here, it will follow that isatty(fileno(stdin)) is something != 0 (likely 1) when executing directly for you and 0 when executing in your script. I checked that with my Debian WSL and could not reproduce that. Are you piping something into the script? Or are you accessing stdin at any place in the script? |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
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 |