빈 행 만들기

빈 행 만들기

현재 여기에 빈 줄을 추가하려고 합니다. 지금까지 사용한 명령의 예는 다음과 같습니다.

echo -e "my kernel version is $(uname -a) \nand the current date is $(date)"

출력이 이렇게 되도록 모든 것을 어떻게 변경합니까?

my kernel version is Linux centos7 3.10.0-1127.18.2.el7.x86_64 #1 SMP Sun Jul 26 15:27:06 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
*** empty line***   
and the current date is Fri Apr 23 09:18:29 EEST 2021

답변1

여기 문서를 사용하여 여러 줄의 메시지가 출력됩니다(여기 문서에 빈 줄을 포함하면 빈 줄이 생성됩니다).

cat <<END
my kernel version is $(uname -a)

and the current date is $(date)
END

printf이는 메시지를 출력 하는 데 사용됩니다 (두 개의 연속된 개행을 출력하여 빈 줄이 생성됩니다).

printf 'my kernel version is %s\n\nand the current date is %s\n' "$(uname -a)" "$(date)"

내 시스템에서는 둘 다 텍스트를 생성합니다.

my kernel version is OpenBSD box.prefix.example.com 6.9 GENERIC.MP#473 amd64

and the current date is Fri Apr 23 17:03:24 CEST 2021

또한보십시오:왜 printf가 echo보다 나은가요?

답변2

나는 그것이 그것 printf보다 더 일반적이라는 데 동의 echo하지만, 빠른 수정은 다음과 같습니다:

에서:

echo -e "my kernel version is $(uname -a) \nand the current date is $(date)"

도착하다:

echo -e "my kernel version is $(uname -a) \n\nand the current date is $(date)"

원하는 만큼 추가해 보세요.개행 문자 \n원하는만큼 공백을 확보하십시오.

관련 정보