Search code examples
linuxbashvariablesscriptingzenity

Line 1 is not working, are not the same these two lines? why?


I hope you can help me with this problem ... I have in following piece of code:

i=1
COMMAND="echo "$((i*19))"; sleep 1; i=$((i+1))"

I have no idea why this line does not work: (Call line 1)

($COMMAND; $COMMAND; $COMMAND; $COMMAND) | zenity --progress --text="BAR PROGRESS!!" --percentage=0 --auto-close

I also tried with:

($((COMMAND)); $((COMMAND)); $((COMMAND)); $((COMMAND))) | zenity --progress --text="BAR PROGRESS!!" --percentage=0 --auto-close

And this line if it works: (call line 2)

(echo "$((i*19))"; sleep 1; i=$((i+1)); echo "$((i*19))"; sleep 1; i=$((i+1)); echo "$((i*19))"; sleep 1; i=$((i+1)); echo "$((i*19))"; sleep 1; i=$((i+1))) | zenity --progress --text="BAR PROGRESS!!" --percentage=0 --auto-close

They are not supposed to be the same ?? (Line 1 and linea2)

What I do is instead of putting put Line 1 Line 2, but is very sloppy and that's why I want to use the line 1 (which has more neat and understandable syntax)

Thank you!!


Solution

  • I would suggest using a for loop instead of attempting to evaluate a string as a command:

    for i in {1..4}; do
        echo $(( i * 19 ))
        sleep 1
    done | zenity --progress --text="BAR PROGRESS!!" --percentage=0 --auto-close