I have the function below for writing storage (sync
on Unix):
# Sync Progress Function
function syncStorage {
printq "Writing storage, may take more than 5 minutes."
printq "Although it seems slow, consider this process like flashing an ISO to a USB Drive."
printq "Below is an innacurate indicator of mB left to write. It may decrease hundreds of megabytes in seconds."
# shellcheck disable=SC2016
sync & {
# If the unsynced data (in kB) is greater than 50MB, then show the sync progress
while [[ $(grep -e Dirty: /proc/meminfo | grep --color=never -o '[0-9]\+') -gt 5000 ]]; do
SYNC_MB=$(grep -e Dirty: /proc/meminfo | grep --color=never -o '[0-9]\+' | awk '{$1/=1024;printf "%.2fMB\n",$1}')
echo -en "\r${SYNC_MB}"
sleep 1
done
}
echo
#watch -n 1 'grep -e Dirty: /proc/meminfo | grep --color=never -o '\''[0-9]\+'\'' | awk '\''{$1/=1024;printf "%.2fMB\n",$1}'\'''
#grep -e Dirty: /proc/meminfo | grep --color=never -o '[0-9]\+' | awk '{$1/=1024;printf "%.2fMB\n",$1}'
}
I want to port it to Powershell, and have done this so far:
sync & {
# If the unsynced data (in kB) is greater than 50MB, then show the sync progress
# You can replace contents in $(...) with 5001 for testing purposes
while ( $(grep -e Dirty: /proc/meminfo | grep --color=never -o '[0-9]\+') -gt 5000 ) {
SYNC_MB=$(grep -e Dirty: /proc/meminfo | grep --color=never -o '[0-9]\+' | awk '{$1/=1024;printf "%.2fMB\n",$1}')
echo -en "\r${SYNC_MB}"
sleep 1
}
}
Powershell accepts this syntax, but returns:
Id Name PSJobTypeName State HasMoreData Location
-- ---- ------------- ----- ----------- --------
45 Job45 BackgroundJob Running True localhost
# If the unsynced data (in kB) is greater than 50MB, then show the sync progress
while ( 43289423 -gt 5000 ) {
SYNC_MB=$(grep -e Dirty: /proc/meminfo | grep --color=never -o '[0-9]\+' | awk '{$1/=1024;printf "%.2fMB\n",$1}')
echo -en "\r${SYNC_MB}"
sleep 1
}
It doesn't run the code, it just prints it out. The same behavior persists when you replace the $(...) with any value (e.g. 5001 to satisfy the while loop) in the while loop's condition. Any ideas?