2017-04-18 3 views
1

저는 BASH에 익숙하지 않고 동일한 2 줄에 2 줄을 어떻게 인쇄 할 수 있을지 궁금합니다.BASH는 동일한 2 줄에 2 줄을 인쇄합니다.

내가하려는 것은 BASH에서 2 줄 진행 바를 만드는 것입니다.

echo -en 'Progress: ###   - 33%\r' 
echo -en 'Progress: #######  - 66%\r' 
echo -en 'Progress: ############ - 100%\r' 
echo -en '\n' 

을하지만 지금은 만 2 개 라인 같은 일을 할 노력하고있어, 모든 것이 지금까지 실패한 시도 : 만들기 1 개 라인 진행률 표시 줄이 오히려 쉽게,이 같은 해.

두 번째 줄에서는 스크립트의 어떤 지점에 있는지, 예를 들어 어떤 변수가 수집 중인지, 어떤 기능이 실행 중인지 등을 알려주는 "진행 세부 정보"를 넣고 싶습니다. 하지만 2 줄 진행률 표시 줄을 만들 수없는 것 같습니다.

+0

미안 친구,하지만 난 당신이 할 수 있다고 생각하지 않습니다. 하지만 같은 줄에 진행을 두지 않는 이유는 무엇입니까 – sjsam

+0

가능한 [쉘 스크립트에 진행률 막대를 추가하는 방법?] (http://stackoverflow.com/questions/238073/how-to-add-a-progress) -bar-to-a-shell-script) –

+0

@djm 아니요, 단 한 줄 진행률 표시 줄 만 다루고 있습니다. 이것은 특히 여러 줄을 요구합니다. – tripleee

답변

0

\033[F을 사용하면 이전 행으로, \033[2K을 사용하면 현재 행을 지울 수 있습니다 (출력 길이가 변경된 경우). 내가 한 스크립트의

:

echo -en 'Progress: ###   - 33%\r' 
echo -en "\ntest" # writes progress detail 
echo -en "\033[F\r" # go to previous line and set cursor to beginning 

echo -en 'Progress: #######  - 66%\r' 
echo -en "\n\033[2K" # new line (go to second line) and erase current line (aka the second one) 
echo -en "test2"  # writes progress detail 
echo -en "\033[F\r" # go to previous line and set cursor to beginning 

echo -en 'Progress: ############ - 100%\r' 
echo -en "\n\033[2K" # new line and erase the line (because previous content was "test2", and echoing "test" doesn't erase the "2") 
echo -en "test"  # write progress detail 
echo -en '\n' 
1

그것은 예를 들어, tputprintf를 사용하여 이중 라인을 덮어 쓸 수있다 :

function status() { 
    [[ $i -lt 10 ]] && printf "\rStatus Syncing %0.0f" "$((i * 5))" ; 
    [[ $i -gt 10 ]] && printf "\rStatus Completing %0.0f" "$((i * 5))" ; 
    printf "%% \n" ; 
} 

for i in {1..20} 
do status 
    printf "%0.s=" $(seq $i) ; 
    sleep .25 ; tput cuu1 ; 
    tput el ; 
done ; printf "0%%\n" ; printf " %.0s" {1..20} ; printf "\rdone.\n" 

한 줄 :

for i in {1..20}; do status ; printf "%0.s=" $(seq $i) ; sleep .25 ; tput cuu1 ; tput el ; done ; printf "0%%\n" ; printf " %.0s" {1..20} ; printf "\rdone.\n" 

루프가 th를 호출합니다. e status은 특정 시간 동안 적절한 텍스트를 표시하는 기능을합니다.

결과 출력은 다음과 유사 할 것입니다 :

Status Completing 70% 
============== 
관련 문제