Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Minor Piping terminal shell script output with eval is inconsistent
#1
When you execute shell scripts inside of shell scripts in the terminal you expect to get some sort of output from the child process and then handle it. You can sort of achieve this by piping the wanted output into echo in the shell script. So if you echo "poo" in the child script, the parent script receives "poo" and can use it for whatever.

However, if you try and do something similar with eval, you get some erratic behaviour.
Let's say we've stored our output in the OUT variable. Doing 'eval OUT' normally outputs the value of OUT on the screen (which I assume is the current pipe or whatever). But if you do 'eval OUT' while inside a script, it does not output anything, therefore a parent script does not get anything from the child.

The only way to get some sort of output is to use 'eval OUT^echo'. This works, but it also duplicates the output. So if we store "poo" in OUT, the parent would receive "poopoo". Terrifying.


This might be convoluted and confusing to understand, but it's a bit easier to reproduce. Here are the scripts for testing:

Code:
echo "#!|neval $(test2) pootis + to temp| eval temp^echo"^test
echo "#!|neval bro to temp| eval temp^echo"^test2


Just run test, and you will notice that it outputs 'brobropootis'. You can also remove the ^echo from test2 - in this setup you will receive no output and running test will fail with stack underflow.

It would be nice to be able to pipe stuff between shell scripts, but currently it's really really difficult.


Forum Jump:


Users browsing this thread: 1 Guest(s)