printf 출력은 다음 줄로 실행됩니다.

printf 출력은 다음 줄로 실행됩니다.

나는 이미 에 있습니다 vi. 내 출력은 그 아래 줄로 실행됩니다. 저는 UNIX를 처음 접했기 때문에 배우려고 노력하고 있습니다. 내 출력은 printf.

printf "%-15s %15s %15s %2d\n %2s " $name $days $phone $start $time

예를 들어 출력은 다음과 같습니다.

name       days       phone      start 

time name    days       phone      start

time name    days       phone      start 

etc...

5개 변수를 모두 같은 줄에 인쇄하려면 어떻게 해야 합니까?

답변1

당신의 명령:

printf "%-15s %15s %15s %2d\n %2s " $name $days $phone $start $time

너의 문제:

'...\n %2s'

앞에 개행 문자를 삽입하려고 합니다 $time. 그러지 마세요. 하다:

printf '%-15s %15s %15s %2d %2s\n' \
    "$name" "$days" "$phone" "$start" "$time"

답변2

@mikeserv의 답변 외에도 다음에서 출력 형식 컨트롤의 전체 목록을 볼 수 있습니다 man 1 printf.

   \"     double quote    
   \\     backslash    
   \a     alert (BEL)    
   \b     backspace    
   \c     produce no further output    
   \e     escape    
   \f     form feed    
   \n     new line    
   \r     carriage return    
   \t     horizontal tab    
   \v     vertical tab    
   \NNN   byte with octal value NNN (1 to 3 digits)    
   \xHH   byte with hexadecimal value HH (1 to 2 digits)    
   \uHHHH Unicode (ISO/IEC 10646) character with hex value HHHH (4 digits)    

   \UHHHHHHHH
          Unicode character with hex value HHHHHHHH (8 digits)    

   %%     a single %    
   %b     ARGUMENT as a string with `\' escapes interpreted, except that 
          octal escapes are of the form \0 or \0NNN

모든 운영 체제에서 명령을 사용하는 man <command name>방법을 배우려면 읽어야 합니다 .*nix

관련 정보