Bash - assigning variables - Yad paned notebook
Bash - assigning variables - Yad paned notebook
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.
&
res1 &
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.
tee -a
#!/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
sysvar
&
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 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 at 23:51
Try putting the
&
inside the $(...)
– Barmar
Aug 24 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 at 0:00
1 Answer
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
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
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 at 22:34