문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
linux:shell_script [2021/05/15 16:52] kwon37xi |
linux:shell_script [2024/01/19 08:09] (현재) kwon37xi |
||
---|---|---|---|
줄 4: | 줄 4: | ||
* [[linux: | * [[linux: | ||
* [[linux: | * [[linux: | ||
+ | |||
+ | ===== 인자 갯수 검사 Argument count ===== | ||
+ | * '' | ||
+ | <code sh> | ||
+ | if [ " | ||
+ | echo " | ||
+ | fi | ||
+ | </ | ||
===== pipe 출력 결과를 그대로 실행하기 ===== | ===== pipe 출력 결과를 그대로 실행하기 ===== | ||
줄 25: | 줄 33: | ||
</ | </ | ||
- | ===== 참조 | + | ===== 다른 명령 Stream 으로부터 지속적으로 결과 읽어서 처리하기 |
+ | * [[https:// | ||
+ | <code sh> | ||
+ | find . -type f | | ||
+ | while read -r line | ||
+ | do | ||
+ | echo " | ||
+ | done | ||
+ | |||
+ | # one liner | ||
+ | find . -type f | while read -r line; do echo " | ||
+ | |||
+ | |||
+ | # 혹은 | ||
+ | |||
+ | while read -r line | ||
+ | do | ||
+ | echo " | ||
+ | done < <(find . -type f) | ||
+ | </ | ||
+ | * [[http:// | ||
+ | |||
+ | ===== 실패시 fallback 처리 ===== | ||
+ | * '' | ||
+ | |||
+ | <code sh> | ||
+ | # curl 명령 실패시에 " | ||
+ | TEST_RESULT=$(curl -Ss https:// | ||
+ | </ | ||
+ | |||
+ | ===== 명령의 존재 검사 ===== | ||
+ | * '' | ||
+ | |||
+ | <code sh> | ||
+ | command -v < | ||
+ | |||
+ | if ! command -v < | ||
+ | then | ||
+ | echo "< | ||
+ | exit | ||
+ | fi | ||
+ | </ | ||
+ | * '' | ||
+ | * '' | ||
+ | <code sh> | ||
+ | if hash gdate 2>/ | ||
+ | gdate " | ||
+ | else | ||
+ | date " | ||
+ | fi | ||
+ | </ | ||
+ | * [[https:// | ||
+ | |||
+ | ===== 참조 ===== | ||
+ | * [[https:// | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
줄 34: | 줄 96: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// |