내 스크립트에 이상한 문제가 있으며 제거 할 수있는 해결책이 있는지 알고 싶습니다.
테스트 할 수 있도록 스크립트에 넣었습니다.
#!/bin/bash
# Clear the screen
clear
# Define the array
ARRAY=("\e[2;3HLine one" "\e[3;3HLine two" "\e[4;3HLine three")
# Change background color to "teal" and foreground color to "black"
echo -e "\e[0;30m\e[46m"
# Print each line one by one on the screen
# This works as expected, nothing to say
echo -e "${ARRAY[0]}"
echo -e "${ARRAY[1]}"
echo -e "${ARRAY[2]}"
# The exact same text, just moved the text below the previous one to make it easier to compare
ARRAY=("\e[6;3HLine one" "\e[7;3HLine two" "\e[8;3HLine three")
# Print the entire array in one shot, to gain speed
# This does not work as expected as there is a "space" at the end of the 2 first lines
echo -e "${ARRAY[@]}"
# Reset the colors to normal
echo -e "\e[0m"
시작하면 2 번째 인쇄에서 1 번째와 2 번째 줄 끝에 "공백"이 있음을 알 수 있습니다.
문제는 이 공간을 제거하는 방법입니다.
참고 :이 포맷이 필요하고 전체 배열을 한 번에 인쇄해야합니다 ... 그런데 이미 IFS 및 문자 대체로 플레이했지만 지금까지 예상대로 작동하지 않았습니다 ...
편집 : " echo "대신 " printf "를 사용하여 바로 아래에 Cyrus가 제안한 솔루션이 예상대로 작동하는 것 같습니다 (내가 "echo"내장 대신 사용하는 장단점은 확실하지 않지만 지금은 일).
해결책 :
printf "%b\n" "${ARRAY[@]}"
대신에 :
echo -e "${ARRAY[@]}"
도움을 주신 Cyrus에게 다시 한 번 감사드립니다.
바꾸다
echo -e "${ARRAY[@]}"
으로
printf "%b\n" "${ARRAY[@]}"
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다