Reputation: 5303
How to execute dialog
in a function, so that another function can use its result ?
function a(){
echo IN A
TMPFILE=$(mktemp)
dialog --nocancel --no-lines --no-button --no-description --menu " -" 20 50 8 \
`echo "$*" | sed 's/^\(.*\)$/\1 ·/g'` 2>$TMPFILE
clear
cat $TMPFILE
}
function b(){
echo IN B
a $* | sed 's/\(.*\)/oo\1oo/g'
}
echo IN PROG
b $*
To execute it, I run :
./aaaa.sh ff1 dd2 ee33 ff66 ll11
And the result is the following. It doesn't display the dialog box, but there are many empty lines where it should have been.
IN PROG
IN B
ooIN Aoo
oo
ff1oo
I have tried to execute it with $(a $*)
or `a $*` , but with no success
Upvotes: 0
Views: 196
Reputation: 601
In your function "b" everything that is on standard output from "a" is sent to "sed". This means that both "dialog" and "cat" have their standard output redirected to "sed" which will break it in the current form.
Here is the fixed version:
function a(){
echo IN A
TMPFILE=$(mktemp)
dialog --nocancel --no-lines --no-button --no-description --menu " -" 20 50 8 \
`echo "$*" | sed 's/\([^[:space:]]\+\)/\1 ·/g'` >&2 2>$TMPFILE
clear
cat $TMPFILE
}
function b(){
echo IN B
a $* | sed 's/\(.*\)/oo\1oo/g'
}
echo IN PROG
b $*
The trick to make it work is to not have "dialog" standard output (the form) send to "sed" from function "b". To achieve that I redirected the standard output of "dialog" to same place as error output is at that time (let's call this the error screen) and then the error output is redirected to the file but this will not affect where the standard output was redirected to (error screen).
I also modified the reg-exp from sed because echo "$*"
will output just one line and I thought you want to add a "." after each argument passed to the script not after all of them.
Upvotes: 1