Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Here is an example of how to use the kdialog progressbar. It works.

dbusRef=`kdialog --progressbar "Press Cancel at Any time" 10`
qdbus $dbusRef showCancelButton true

until test "true" = `qdbus $dbusRef wasCancelled`; do
 sleep 1
 inc=$((`qdbus $dbusRef Get "" "value"` + 1))
 qdbus $dbusRef Set "" "value" $inc;
done

qdbus $dbusRef close

However, I can't figure out how to make it work when the main script file calls a 2nd script file. I want to keep updating the same progress bar from the second script.

The error is:

  • qdbus Set '' value 53 Path '' is not a valid path name.

The code to update the progressbar is exactly the same in the second script file as the first. Generically, it is this:

qdbus $dbusRef Set "" value "$PROGRESS"

Obviously, some variable values are not getting passed around. But none of the tutorials I have seen explain the variables. For example, what is value? What is $dbusRef?

In short, how do I update the same progressbar from a second bash script file that is called by the first?

share|improve this question
    
Just a sanity check: did you maybe forget to export the variables? –  Joseph R. Jul 13 '13 at 23:37
    
Thanks for the edits and, yes, it looks like export will do it. I didn't forget -- just didn't yet know how to do it. –  MountainX Jul 14 '13 at 6:08
add comment

1 Answer

up vote 2 down vote accepted

You forgot to post both scripts. But given your description, it looks like you're setting the variable dbusRef in one shell script, and accessing it in another script. This doesn't work because each shell has its own set of variables. You need to pass the variable from the calling script to the called script.

An easy way of doing this is to turn the variable into an environment variable. You do this with the export builtin. In the caller:

export dbusRef="$(kdialog --progressbar "Press Cancel at Any time" 10)"
…
some_other_program_that_happens_to_also_be_a_shell_script

In the called script:

PROGRESS='something or other'
qdbus "$dbusRef" Set "" value "$PROGRESS"

Alternatively, instead of using export you can use any method you like to pass the information, such as a command line argument.

dbusRef="$(kdialog --progressbar "Press Cancel at Any time" 10)"
…
some_other_program_that_happens_to_also_be_a_shell_script argument1 argument2 "$dbusRef" argument4

and in the called script:

PROGRESS='something or other'
qdbus "$3" Set "" value "$PROGRESS"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.