카테고리 보관물: bash

[bash] 반올림 하기

bash shell 에서 소수점 반올림 하는 방법을 소개합니다. 아주 간단하기 때문에, 아래 예시만 보면 해결이 되실 겁니다. 짧은 포스팅을 마치며, 이글이 누군가에게 도움이 되기를 바랍니다.

카테고리: bash, ICT, Language, sh | 태그: , , , , , , , , , , , | 댓글 남기기

[bash] how to split a string with a delimiter

You can split a string with a delimiter, as the command below. string=”This is a test string” delimiter=’ ‘ IFS=$delimiter read -ra result <<< “$string” result_cnt=${#result[@]} for (( i=0; i<$result_cnt; i++ )) do echo “${result[$i]}” done Output

카테고리: bash, sh | 태그: , , , , | 댓글 남기기

[bash] How to round floating point numbers

Use the round function, as the command below. #!/bin/bash round() { echo $(printf %.$2f $(echo “scale=$2;(((10^$2)*$1)+0.5)/(10^$2)” | bc)) }; test=6.6666 echo $(round $test 0) # output : 7 echo $(round $test 1) # output : 6.7 echo $(round $test 2) … 계속 읽기

카테고리: bash, 미분류, sh | 태그: , , | 댓글 남기기

[bash] How to insert a string into a text variable at specified position

To insert a string into the variable ‘text’ at position ‘p’, refer to the command below. p=5 text=”text variable” text=”${text:0:p}a string${text:p}”  

카테고리: bash, sh | 태그: | 댓글 남기기