Solved Dialog: prgbox there is no output (no echoing output)

Márcio Rezende

Member

Reaction score: 34
Messages: 37

Hi, pals.

I'm trying to convert an old bash script that runs normally in cygwin and linux.

For some reason the same command is not working on my FreeBSD box.

It is just one line that supose to echo command output when used with command dialog --prgbox.

If I use eval to execute bash (forking it) it comes with some error after displaying my motd message as if I logged in interactively.

This is the command without eval: empty output
Bash:
dialog --stdout --no-collapse --backtitle "My Fantastic System" --title "Welcome!" --ok-label "Ok" --title "Backups Logs " --prgbox " " "echo there is no echo" "20" "64"

If I use eval, something weird occurs: motd message appear as if I logged in interactively.

Bash:
dialog --stdout --no-collapse --backtitle "My Fantastic System" --title "Welcome!" --ok-label "Ok" --title "Backups Logs " --prgbox " " "$(eval bash echo there is no echo)" "20" "64"

Plataform: PC Intel
FreeBSD version: 12.1-RELEASE r354233
Bash version: GNU bash, versão 5.0.17(0)-release (amd64-portbld-freebsd12.1)
Dialog version: 1.2-20130923
 

Attachments

  • Screenshot_20200821_205023.png
    Screenshot_20200821_205023.png
    27.2 KB · Views: 78

ekvz

Well-Known Member

Reaction score: 281
Messages: 431

I am not exactly sure what you are trying to archive and i also dont know why the first command results in an empty box but the second command pretty much has to fail.

Code:
bash echo there is no echo

Is not going to execute echo with there, is, no and echo as parameters. At least not in the expected way. It will actually instruct bash to look for a shell script called echo and parse it. On my system it happens to find /bin/echo and aborts because it's obviously not a shell script but a binary file. I think what you want is rather this:

Code:
bash -c 'echo there is no echo'

Besides that i am pretty sure the eval in front of your command is superfluous. There is nothing on the line that would be expanded so it doesn't change anything. The $( ... ) substitution is likely not what you want either since i think if the rest the command actually succeeded it would result in dialog trying to execute a command named there with parameters of is, no and echo.

On a side note executing bash just for echo (or any other non bash specific commands) is a bit wasteful as sh would give the same result while using less resources.
 
OP
Márcio Rezende

Márcio Rezende

Member

Reaction score: 34
Messages: 37

Ok rephrasing.

My intent is to run a command - a bash script - as argument for dialog --prgbox.

I can run that command in other systems using bash. But for some unknown reason, those bash scripts are returning empty output on my FreeBSD box, inasmuch in other systems - Debian and Cygwin - that script is running normally and returning output to dialog as expected.

in first command sample I forgot to quote arguments. (misstyped here, srry!)

Second example - I knew eval is not necessary there. That was a desperated overkill try to do it work.

In this way I can receive output but it is was returning - in FreeBSD - my fortune message (it was a tip that something worked, but not my script). So I disabled it in my .profile. It fixed, fortune mess, but there is no outpu at all.

To demonstrate I've prepared two scripts and put it in homedir of those three systems. Outputs is attached.

So the question is why dialog behaviour is different in freebsd?
How to fix it or workaround ?


Bash:
#!/usr/bin/env bash
# script master: dlg.bash

title=":-))) My output is:"
[[ $OSTYPE =~ "freebsd" ]] && title=":-((( No output !"


dialog --stdout --backtitle "Running in $OSTYPE" \
       --ok-label "Ok" --title "$title" \
       --prgbox "./myscript.bash" "bash ./myscript.bash" \
       "20" "64"


Bash:
#!/usr/bin/env bash
# scprit slave: myscript.bash

# command 1
uname -a

# command 2
cat ./myscript.bash


Running in FreeBSD
freebsd.png

Running in Debian

debian.png


Running in Cygwin

cygwin.png
 
OP
Márcio Rezende

Márcio Rezende

Member

Reaction score: 34
Messages: 37

Ok, problem is not over but for now I managed to devise which is the source of trouble: bash.

In FreeBSD it seems that dialog --prgbox option call shell - instead bash - to execute scripts, even with default shell configured accordingly at passwd file and using shebang pointing to bash path.

Passing a valid (or compatible) script it runs but if there is specific bash commands - [[ or declare, for instance - it cannot run. Even if shebang #!/usr/bin/env bash is provided.

Solution: rewrite called script useing sh/posix or rework dialog code to accept to drive bash in --prgbox option.

I've discovered it after using --trace option of dialog.
 
Top