문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
linux:bash [2015/06/16 23:14] kwon37xi |
linux:bash [2019/09/10 13:10] kwon37xi [Editor로 명령 편집하기] |
||
---|---|---|---|
줄 1: | 줄 1: | ||
====== Bash ====== | ====== Bash ====== | ||
+ | ===== Oh My Bash ===== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
===== Redirect ===== | ===== Redirect ===== | ||
* http:// | * http:// | ||
줄 12: | 줄 16: | ||
* '' | * '' | ||
+ | ===== 실행 결과 변수에 저장 ===== | ||
+ | <code sh> | ||
+ | # $(명령어) 문법 | ||
+ | test=$(basename " | ||
+ | # backquote `명령어` 문법 | ||
+ | test=`basename " | ||
+ | </ | ||
===== 16진수/ | ===== 16진수/ | ||
<code sh> | <code sh> | ||
줄 27: | 줄 38: | ||
</ | </ | ||
[[http:// | [[http:// | ||
+ | |||
+ | ===== for loop 숫자 ===== | ||
+ | [[http:// | ||
+ | <code sh> | ||
+ | for i in $(seq -f " | ||
+ | do | ||
+ | echo $i | ||
+ | done | ||
+ | |||
+ | # 결과 | ||
+ | 00010 | ||
+ | 00011 | ||
+ | 00012 | ||
+ | 00013 | ||
+ | 00014 | ||
+ | 00015 | ||
+ | </ | ||
+ | |||
+ | <code sh> | ||
+ | # printf 사용 | ||
+ | i=99 | ||
+ | printf " | ||
+ | # 결과 | ||
+ | 00099 | ||
+ | |||
+ | # 결과를 변수에 저장하기 -v | ||
+ | i=99 | ||
+ | printf -v j " | ||
+ | echo $j | ||
+ | #결과 | ||
+ | 00099 | ||
+ | </ | ||
+ | |||
+ | bash 4.x 에서는 | ||
+ | <code sh> | ||
+ | for i in {00..10}; do | ||
+ | echo $i | ||
+ | done | ||
+ | # 결과 | ||
+ | 00 | ||
+ | 01 | ||
+ | 02 | ||
+ | 03 | ||
+ | 04... | ||
+ | </ | ||
+ | |||
===== 변수에 값 입력 받기 ===== | ===== 변수에 값 입력 받기 ===== | ||
<code sh> | <code sh> | ||
줄 78: | 줄 135: | ||
</ | </ | ||
* '' | * '' | ||
+ | |||
+ | ===== File Path dir/ | ||
+ | <code sh> | ||
+ | dirname "/ | ||
+ | basename "/ | ||
+ | </ | ||
+ | |||
+ | ===== Filename name / extension 분리 ===== | ||
+ | * [[http:// | ||
+ | filename=$(basename " | ||
+ | extension=" | ||
+ | filename=" | ||
+ | </ | ||
+ | |||
+ | ===== User Input 사용자 입력 ===== | ||
+ | * http:// | ||
+ | * '' | ||
+ | read varname # varname 으로 입력값 저장 | ||
+ | read -p 'press enter' varname # prompt | ||
+ | </ | ||
+ | |||
+ | ===== shell script 파라미터 갯수 검사 ===== | ||
+ | [[http:// | ||
+ | <code sh> | ||
+ | if [ $# -eq 0 ] | ||
+ | then | ||
+ | echo "No arguments supplied" | ||
+ | exit | ||
+ | fi | ||
+ | |||
+ | # 혹은 특정 파라미터가 "" | ||
+ | if [ -z " | ||
+ | then | ||
+ | echo "No argument supplied" | ||
+ | exit | ||
+ | fi | ||
+ | </ | ||
+ | |||
+ | ===== Editor로 명령 편집하기 ===== | ||
+ | * '' | ||
+ | * '' | ||
+ | bind -m vi-insert '" | ||
+ | </ | ||
+ | * 위 명령 실행후 '' | ||
===== 참조 ===== | ===== 참조 ===== | ||
줄 90: | 줄 191: | ||
* [[https:// | * [[https:// | ||
* [[http:// | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||