![창 테두리 끝에 개행 문자를 사용하여 줄을 에코하는 방법은 무엇입니까? [복사]](https://linux55.com/image/4292/%EC%B0%BD%20%ED%85%8C%EB%91%90%EB%A6%AC%20%EB%81%9D%EC%97%90%20%EA%B0%9C%ED%96%89%20%EB%AC%B8%EC%9E%90%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EC%A4%84%EC%9D%84%20%EC%97%90%EC%BD%94%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F%20%5B%EB%B3%B5%EC%82%AC%5D.png)
모든 목록을 TAB으로 구분하여 한 줄에 표시하고 싶습니다( ls
폴더의 파일 처리와 같이).
for i in one two some_are_very_long_stuff b c; do echo $i; done
단어당 한 줄씩 인쇄합니다.
one
two
some_are_very_long_stuff
b
c
ls
대신 옵션이 없는 것처럼 중단하고 싶습니다 .
mkdir /tmp/test
cd /tmp/test
for i in one two some_are_very_long_stuff b c z; do touch $i; done
ls
출력됩니다
b one two
c some_are_very_long_stuff z
답변1
columns
GNU 명령을 사용할 수 있습니다 autogen
.
$ seq 60 | columns
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60
Pass 다음을 zsh
사용할 수 있습니다 print -C
.
$ print -C4 {1..20}
1 6 11 16
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
$ print -aC4 {1..20}
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
먼저 정렬해야 하는 경우(예: 다음과 같이 ls
):
$ print -oC4 {1..20}
1 14 19 5
10 15 2 6
11 16 20 7
12 17 3 8
13 18 4 9
답변2
echo
매뉴얼 페이지 에서 :
-n do not output the trailing newline
-e enable interpretation of backslash escapes
If -e is in effect, the following sequences are recognized:
...
\t horizontal tab
그러면 이렇게 됩니다:
for i in one two some_are_very_long_stuff a b c d e f g h i j k l m n o; do
echo -en "$i\t";
done; echo