Bash. infinite loop showing a counter and more info -
i have script generates dinamically bash script. in heredoc script there infinite loop showing counter (this works!):
date1=`date +%s` while true; echo -ne "$(date -u --date @$((`date +%s` - $date1)) +%h:%m:%s)\r"; done
this loop working fine if put this. problem need show not counter. more info needed (some static data). i'll put not working code:
#!/bin/bash dir="/tmp/" my_file="generatedscript.sh" rm -rf "$dir$my_file" > /dev/null 2>&1 exec 3>"$dir$my_file" cat >&3 <<-'eof' #!/bin/bash date1=`date +%s` while true; echo -ne "info\n" # damned line, if remove counter works fine echo -ne "time counter: $(date -u --date @$((`date +%s` - $date1)) +%h:%m:%s)\r"; done eof exec 3>&- xterm -hold -geometry 78x25+0+0 -t "testing" -e "bash \"$dir$my_file\"" > /dev/null 2>&1 &
this shows xterm window lot of lines , info line overlapped "time" word of other line. want show info line separately time counter line , counter running... , once!
if remove line echo -ne "info\n" counter showing ok, running , once... how can put different line (echo info) above , fixed line without repetition? possible? idea of how reach this? thank you.
just move info line out of loop. prefer put carriage return @ start of line. neither -n
or -e
portable, prefer printf
simplest uses of echo
.
dir="/tmp/" my_file="generatedscript.sh" script="$tmp/$my_file" cat > "$script" <<'eof' echo info date1=$(date +%s) while true; now=$(date +%s) delta=$((now - date1)) printf '\rtime counter: %s' "$(date -u --date "$delta" +%h:%m:%s)" done eof chmod +x 500 "$tmp/$my_file" xterm -hold -geometry 78x25+0+0 -t "testing" -e "$script" > /dev/null
Comments
Post a Comment