# How to create a progress bar using Wolframscript?

I am using Wolfram script with a Mac OS. I have a long while loop dependent on the length of a list. i.e.:

myList = {}
While[ Length[myList] < 100, myList = AppendTo[myList, 0]]


How do I get a progress bar to appear in my terminal during this while loop?

• That code does not make sense because myList is not defined, While does not have a test and a body separated by coma and if you put the coma that loop is infinite cause you are not increasing the length of myList. Jan 26 '20 at 14:36
• It's an example, the point of the question is about the progress bar. "Corrected code": myList = {}; While[ Length[myList] < 100, myList += {0,0}] Jan 26 '20 at 18:01
• Still an infinite loop. Jan 26 '20 at 18:39

This solution is specific to Linux

k=1;

While[ k<100,

k++; Pause@.1;

(* progress indicator *)
Run[ "echo -n '" <>
StringRepeat["|",k] <>
StringRepeat["-", 100-k] <>
"\r'"]
]


but you might find a command line that overwrites previous outputs like echo -n ' \r' for other systems too.

• hmm wolfram script doesn't seem to understand the return carriage. It prints on a new line every iteration. BTW I'm using a UNIX system so it should work Jan 26 '20 at 21:27
• It is not wolfram that do not understand the return carriage, it is the shell of your operating system. As I wrote in the answer, you need to find command line that works for your OS. Jan 28 '20 at 14:48
• Hmm using the above code and substituting the Run command for a WriteString command I get the expected output. This solution works for bash shells on Linux OS Jan 29 '20 at 15:19
• @PHPHacky Great. I am on Debian 9 and only Run gives me the expected behaviour, not WriteString, What OS is yours? Jan 29 '20 at 15:25
• macOS (which is Unix based) but I tested this on Linux as well. What shell are you using? Jan 29 '20 at 17:44