1

Following on from this question, and changing the question, another way to write the Yad notebook script is as follows. This removes the & from res1 & and asynchronous operation.

As mentioned @Barmar, "scripts operate sequentially, whereas there is no way to have multiple variable assignments start concurrently and wait for a different pane to get a response." Which is probably the answer to this question.

This is one solution but it creates a file for the output of both Yad panes. Could be one file with tee -a on the second pane and trimming characters with sed? Not the most elegant solution. And it fails on the number of characters.

#!/bin/bash
#ifs.sh

# no AT bridge
    export NO_AT_BRIDGE=1

# yad notebook key
    key=$RANDOM

# system management tab 
    sysvar=$(yad --plug=$key --tabnum=2 --form --columns=1 --editable --separator='' \
        --text="<b>Text</b>" \
        --field="Threads":NUM \
            '3!1..4!1!0' \
        --field="Memory":SCL \
            '50!10..100!1!0' | tee 0 ) &> res2 &

    provar=$(yad --plug=$key --tabnum=1 --form  --columns=1 --editable --separator='' \
        --text="<b>Text</b>" \
        --field="Format":CB \
            'RAW!OTHER' \
        --field="Calibrate":CHK \
            'TRUE!FALSE' | tee 1 )  &> res1 &

    yad --notebook --key=$key --center --tab="<b>Process and options</b>" --tab="<b>System settings</b>" \
        --text="Text" \
            --title="Asterism" \
        --buttons-layout=spread \
        --button=Quit:1 \
        --button=Process:0 2>/dev/null 

    ret=$?

    if [ $ret -eq 0 ]; then

    value=`cat 0`
    values=`cat 1`

    processors=$(echo "$value" | sed s'/.........$//')
    memlimit=$(echo "$value" | sed 's/^........//')

    echo $processors $memlimit

    raw=$(echo "$values" | sed s'/.....$//')
    cal=$(echo "$values" | sed 's/^...//')

    echo $raw $cal

    fi
exit

and, this is the output...

+ sysvar=3.00000050
+ provar=RAWFALSE
+ ret=0
+ '[' 0 -eq 0 ']'
++ cat 0
+ value=3.00000050
++ cat 1
+ values=RAWFALSE
++ echo 3.00000050
++ sed 's/.........$//'
+ processors=3
++ echo 3.00000050
++ sed 's/^........//'
+ memlimit=50
+ echo 3 50
3 50
++ echo RAWFALSE
++ sed 's/.....$//'
+ raw=RAW
++ echo RAWFALSE
++ sed 's/^...//'
+ cal=FALSE
+ echo RAW FALSE
RAW FALSE
+ exit
GeorgeC
  • 81
  • 2
  • 9
  • You're setting `sysvar` to a string, not an array. Also, running the assignment in the background with `&` means it runs in a subshell, so it doesn't affect the original shell's variables. – Barmar Aug 24 '18 at 22:34
  • The correct way to do it is shown in the answers you linked to. Why don't you do it like that? – Barmar Aug 24 '18 at 22:35
  • The difference is standalone Yad dialogues vs paned notebook. The & from what I can tell passes the Yad dialogue to the notebook. I have tried without & and it fails the notebook. – GeorgeC Aug 24 '18 at 23:51
  • Try putting the `&` inside the `$(...)` – Barmar Aug 24 '18 at 23:59
  • But I suspect you can't do it like this. scripts execute commands sequentially, there's no way to have multiple variable assignments start concurrently, and each wait for a different pane to get a response. – Barmar Aug 25 '18 at 00:00
  • That confirms my obervation. It is printing as a string. Thanks – GeorgeC Aug 25 '18 at 00:00
  • If you want to assign as an array, put `()` around the value: `sysvar=($(yad ...))` – Barmar Aug 25 '18 at 00:01
  • ($(yad ...)) was the original syntax. $(yad...) prints a string as does `yad ...` the closest I get is with $(`yad ...`) which prints to the terminal as an array but nothing else. awk is a solution but I wanted to do this in bash. – GeorgeC Aug 25 '18 at 00:17
  • awk doesn't have any way to get the output of asynchronous commands either. – Barmar Aug 25 '18 at 00:18
  • ($(yad... | awk 'BEGIN { FS = ":" } ; { print $0 }' > $syslog | &> res1 &)) works... but generates a file. I have tried a multitude of variations to get this to work. Some characters are not printing in these comments so I might change the question. – GeorgeC Aug 25 '18 at 00:21
  • That's unrelated to the problem, which is that you can't assign variables asynchronously. – Barmar Aug 25 '18 at 00:23
  • All that `awk` command is doing is translating `:` delimiters to space. – Barmar Aug 25 '18 at 00:23
  • OK. Thanks, to avoid lengthy discussion I will spend some time working with your feedback and come back to this later. – GeorgeC Aug 25 '18 at 00:25
  • changed question - provided a solution...? – GeorgeC Aug 26 '18 at 12:58

1 Answers1

1

EDIT: This is a bash solution using sed. Write the yad output to file and edit with sed, rather than attempting to create variables from the yad string - no point.

EDIT: using cut https://stackoverflow.com/a/52055600/5057161

#!/bin/bash
#ifs.sh

# no AT bridge
    export NO_AT_BRIDGE=1

# yad notebook key
    key=$RANDOM

# system management tab 
    yad --plug=$key --tabnum=2 --form --columns=1 --editable --separator=':' \
        --text="<b>Text</b>" \
        --field="Threads":NUM \
            '3!1..4!1!0' \
        --field="Memory":SCL \
            '50!10..100!1!0' > sys | > res2 |

    yad --plug=$key --tabnum=1 --form  --columns=1 --editable --separator=':' \
        --text="<b>Text</b>" \
        --field="Format":CB \
            'RAW!OTHER' \
        --field="Calibrate":CHK \
            'TRUE!FALSE' > pro | > res1 |

    yad --notebook --key=$key --center --tab="<b>Process and options</b>" --tab="<b>System settings</b>" \
        --text="Text" \
            --title="Asterism" \
        --buttons-layout=spread \
        --button=Quit:1 \
        --button=Process:0 2>/dev/null

    ret=$?

    if [ $ret -eq 0 ]; then

    thd=$(echo | sed 's/.......:.*//' < sys)
    mem=$(echo | sed 's|........:||;s/:$//' < sys)

    img=$(echo | sed 's/:.*//' < pro)
    cal=$(echo | sed 's/:$//;s|.*:||' < pro)

    fi

    rm sys pro
exit
GeorgeC
  • 81
  • 2
  • 9