-
Designing Program OutputIoT 과정 2017. 7. 6. 09:51반응형
Variable Attributes(typeset)
typse -L10 var_name
or
typeset -L10 var_name="value string"
Attribute/typeset option/sample
Left Justify -L "string "
Right Justify -R " string"
Lower Case -l "string"
Upper Case -u "STRING"Display Formatted Data
Formatted: print "$var"
Unformatted: print $var
Conversion: printf "%.10s" "$var" //built-in cmd인 print와 다르게 external cmd인 printf는 c언어의 printf와 같다. man printf 커맨드로 메뉴얼 페이지에서 확인#! Formatted, Unformatted의 예..
$ var='this is a test string'
$ print $var
this is a test string
$ print "$var"
this is a test string
$ var='this is a test string'
$ print $var
this is a test string //여러 공백들이 하나로 대체된다.
$ print "$var"
this is a test string //의도한 string이 출력된다
$ cp file1 file2 //shell은 공백의 중복을 하나의 공백으로 대체하므로 이러한 명령도 의도대로 잘 사용된다. 물론 의도한 공백을 넣은 string을 출력할 땐#! printf의 예...
#!/usr/bin/sh
# printf.sh
# conversion at output timevar="posix shell programming"
# notice, printf does not produce an automatic linefeedprintf "%.5s" "$var"
# output is converted to a 5 character string
# output: "posix"$printf "%30s" "$var"
# output is extended to right justified 30 char string
# no linefeed before the next shell prompt '$'
# output: "posix shell programming "$
printf "%-30s" "$var"
# output is extended to left justified 30 char string
# output: " posix shell programming"$printf "\n%.11s\n" "$var"
# output is trimmed to 11 characters, linefeed addedprintf "Interpreter:%11s\n" "$var"
# output includes some added text, then 11 charactersexit
UNIX Command Reference Section알아도 한 번 더 보고 갈만큼 유용cut : Extract datagrep : Search/extracttail : Show last n lineswc : General countersort : Sorts datatr : Translate/Squees;Change old to newpr : Print files!! 아래는 처음보지만 흥미로운 기능tputcursor 이동, 텍스트 줄긋기, 드래그 한 것 처럼 하이라이팅 할 때, 로그인 페이지에서 비밀번호 칠 때처럼 글자 안보이게 입력하기(echo 해제) 등과 같은 기능들을 수행할 수 있다.Command to enable/disable the capnamesCursor Positioningone common capnames to control the cursor positionhome : Moves cursor to the top left corner of the screen (home position)cup x y : Sets cursor position; needs ros (x) and column (y) down from the home positioncuu1, cud1, cub1, cuf1 : Sets cursor {up, down, left, forward} one lineSome useful shell variablesCOLUMNS : Sets the number of columns in the current windowLINES : Sets the number of rows in the current window$ cat middle.sh#!/usr/bin/sh# middle.sh# print in the middle of the window# use an alias to save typing lateralias go="tput cup"back="$(tput cub1)"tput clear# find the middle of the screen (bc is a calculator tool)mid_col="$(print $COLUMNS/2 | bc)"mid_row="$(print $LINES/2 | bc)"# position the cursor in the middle of the screengo $mid_row $mid_col# backup half the width of the text stringprint -n "${back}${back}${back}"print -n "MIDDLE"# move to the last line in the windowgo $LINES 1exit반응형'IoT 과정' 카테고리의 다른 글
Branches and Logic Testing (0) 2017.07.06 Shell Arithmetic (0) 2017.07.06 Designing Program Output (0) 2017.07.06 User Input (0) 2017.07.05 Variable (0) 2017.07.05 Shell Scripting (0) 2017.07.05