"Bash"의 두 판 사이의 차이
ph
10번째 줄: | 10번째 줄: | ||
=={{c|getopt}}== | =={{c|getopt}}== | ||
+ | ===long options=== | ||
+ | use {{c|getopt}}(not {{c|getopts}}) [http://stackoverflow.com/a/402410/766330] | ||
+ | |||
===multiple arguments with one flag === | ===multiple arguments with one flag === | ||
깔끔한 방법이 없어보임. [http://stackoverflow.com/questions/7529856/bash-getopts-retrieving-multiple-variables-from-one-flag] | 깔끔한 방법이 없어보임. [http://stackoverflow.com/questions/7529856/bash-getopts-retrieving-multiple-variables-from-one-flag] | ||
15번째 줄: | 18번째 줄: | ||
이런식으로 계속 주는 수밖에 없는듯 | 이런식으로 계속 주는 수밖에 없는듯 | ||
− | === | + | ===default option {{c|getopt}}=== |
− | + | $ getopt -s bash -o l:: -l list:: -- -ltest | |
+ | -l 'test' -- | ||
+ | $ getopt -s bash -o l:: -l list:: -- --list foo | ||
+ | --list '' -- 'foo' | ||
+ | $ getopt -s bash -o l:: -l list:: -- --list=foo | ||
+ | --list 'foo' -- | ||
+ | {{c|::}}을 쓰면 되지만, optional argument를 명시할 때는 short option의 경우 option뒤에 바로 붙여야 하고 long option의 경우 =을 꼭 써주어야 한다. | ||
− | + | {{break}} | |
− | |||
==bash expansion : ranges== | ==bash expansion : ranges== |
2017년 4월 10일 (월) 14:21 판
목차
manual, refs
- Mendel Cooper - Advanced Bash-Scripting Guide (aka. ABS) (한글판)
- Bash Reference Manual
- bash features
- BASH Programming - Introduction HOW-TO ★
- Bash Guide for Beginners
- Bash scripting Tutorial
getopt
long options
use getopt(not getopts) [1]
multiple arguments with one flag
깔끔한 방법이 없어보임. [2]
-o a1 -o a2 -o a3
이런식으로 계속 주는 수밖에 없는듯
default option getopt
$ getopt -s bash -o l:: -l list:: -- -ltest -l 'test' -- $ getopt -s bash -o l:: -l list:: -- --list foo --list -- 'foo' $ getopt -s bash -o l:: -l list:: -- --list=foo --list 'foo' --
::을 쓰면 되지만, optional argument를 명시할 때는 short option의 경우 option뒤에 바로 붙여야 하고 long option의 경우 =을 꼭 써주어야 한다.
bash expansion : ranges
$ echo {d..h} d e f g h $ echo {d..Z} d c b a _ ^ ] [ Z
For more information, refer wiki.bash-hackers.org.
redirection
### cp file1 file2와 같다 $ cat < file1 > file2
string : $''
$ # Single quotation in single qoute $ # http://stackoverflow.com/a/16605140/766330 $ echo \'sdlfkjsldf\' | sed $'s/\'//' sdlfkjsldf' $ # $'string' : this is special. $ # below line won't work. $ # echo \'sdlfkjsldf\' | sed 's/\'//‘
or
$ # 'or' $ if [ -z "$1" ] || [ -z "$2" ]; then > echo "Usage: `basename $0` rslt_file target_folder" > fi
extract tar archive from stdin
use -
as the input file
cat largefile.tgz.aa largefile.tgz.ab | tar zxf -
find out what is using TCP port 80
# netstat -tulpn | grep :80
-p : You should be root
read from file or stdin
while read line do echo "$line" done < "${1:-/dev/stdin}”
${1:-…}
takes $1
if defined otherwise the file name of the standard input of the own process is used
no op
:
$ if true; then :; else echo; fi
Default .bashrc
/etc/skel/.bashrc
Tar the output on the fly
The same -f - option works for tarring as well.
tar -cf - something | tar -C somefolder -xvf -
GNU tar uses stdio by default:
tar -c something | tar -C somefolder -xv