shellscript에 대하여

28
Shellscript에 대하여 Luavis/sherlock.py

Upload: luavis-kang

Post on 08-Feb-2017

60 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Shellscript에 대하여

Shellscript에�대하여

Luavis/sherlock.py

Page 2: Shellscript에 대하여

Intro

Lightning�Talk

Page 3: Shellscript에 대하여

Intro

Page 4: Shellscript에 대하여

Intro

오랜만에�해보는�언어�공부

Page 5: Shellscript에 대하여

Intro

Shellscript

A�shell�script�is�a�computer�program�designed�to�be�run�by�the�Unix�shell,�a�command-line�interpreter.

Page 6: Shellscript에 대하여

Ksh Bashsince�1987since�1983

History

Page 7: Shellscript에 대하여

Assignment

a=10

b=‘10’

b=“10”

local�b=“10”

export�b=10

b=Hello\�World

b=“Hello�World”

Page 8: Shellscript에 대하여

Array

a=(1�2�3�4)

a=(1�“2”�“3”�“4”)

다중배열�불가

Page 9: Shellscript에 대하여

Array

a=(1�2�3�4)

a=(1�“2”�“3”�“4”)

다중배열�불가

Page 10: Shellscript에 대하여

Array

array_name=("value�1"�"value�2"�"value�3")���echo�"array_name[0]�����=�${array_name[0]}"�echo�"array_name[2]�����=�${array_name[2]}"��echo�"array_name[*]�����=�${array_name[*]}"��echo�"array_name[@]�����=�${array_name[@]}"��echo�"array_name�index��=�${!array_name[@]}"�echo�"array_name�size���=�${#array_name[@]}"�echo�"array_name[0]�size=�${#array_name[0]}"

Page 11: Shellscript에 대하여

Array

array_name[0]�����=�value�1�array_name[2]�����=�value�3�array_name[*]�����=�value�1�value�2�value�3�array_name[@]�����=�value�1�value�2�value�3�array_name�index��=�0�1�2�array_name�size���=�3�array_name[0]�size=�7

Page 12: Shellscript에 대하여

String�concat

Page 13: Shellscript에 대하여

Numeric�expression

a=10�b=20�

c=$(($a�+�$b))�c=`expr�$a�+�$b`

Page 14: Shellscript에 대하여

If�statement

if�[�<case>�];�then�<statements>�

elif�[�<case>�];�then�<statements>�

else�<statements>�

fi

Page 15: Shellscript에 대하여

Comparison�operator�(numeric)

$A�-gt�$B�

$A�-lt�$B�

$A�-ge�$B�

$A�-le�$B�

$A�-eq�$B�

$A�-ne�$B

A가�B보가�크다������

A가�B보다�작다.�

A가�B보다�크거나�같다.������

A가�B보다�작거나�같다.�

A와�B가�같다.������

A와�B가�다르다.

Page 16: Shellscript에 대하여

"string1"�=�"string2"�

"string1"�!�"string2"�

-z�"string"�

-n�"string"

두�문자열이�같은�경우�

두�문자열이�다른�경우�

문자열의�길이가�0인�경우�

문자열의�길이가�0이�아닌경우

Comparison�operator�(string)

Page 17: Shellscript에 대하여

Logical�operator

-a�:�and�-o�:�or

Page 18: Shellscript에 대하여

If�statement�example

a=20�

if�[�$a�-gt�10�-a�$a�-lt�20�];�then�����echo�"10과�20�사이"�elif�[�$a�-gt�20�-a�$a�-lt�30�];�then�����echo�"20과�30�사이"�else�����echo�"아몰랑"�fi

Page 19: Shellscript에 대하여

For�loop�statement

max=10�for�((�i=1;�i�<=�$max;�i++�))�do�����echo�"$i"�done

for�i�in�{{1..10}}�do�����echo�"$i"�done

for�i�in�1�2�3�4�5�6�7�8�9�10�do�����echo�"$i"�done

Page 20: Shellscript에 대하여

Switch-case�statement

case�<variable>�in�<patter1>)�����<statements>�����<statements>;;�<pattern2>)�����<statements>;;�����<statements>;;�*)�����<statements>�����<statements>;;�esac

Page 21: Shellscript에 대하여

Function

function�two_sum_func()�{����sum=$(($1�+�$2))�����return�$sum�}�

two_sum_func�result=$?

Page 22: Shellscript에 대하여

Function

Return은�숫자만�가능

Page 23: Shellscript에 대하여

Function

result=“”�function�get_hello_world()�{���result=“Hello�World”�}�

get_hello_world�echo�“$result”

Page 24: Shellscript에 대하여

사용�예

Install�script�

Build�script�

Dotfiles

Page 25: Shellscript에 대하여

이�언어를�조금만�써보면�느끼는�점

Page 26: Shellscript에 대하여

♚♚Sherlock☆py♚♚�다운시$$당신도�스크립트�마스터

☜☜뒷면100%가능※�♜손쉬운�

파이썬♜편한�사용법�¥�개발참여¥기회@@@�즉시이동�https://pypi.python.org/pypi/sherlock.py

Page 27: Shellscript에 대하여

1. 일단�문법이�파이썬

2. 자주�사용하는�구문�패키징

3. unix-shell뿐만�아니라windows�batch�파일까지

Sherlock.py는..

Page 28: Shellscript에 대하여

감사합니다.

Reference

* http://www.dreamy.pe.kr/zbxe/CodeClip/3765734�* https://wikipedia.org�* http://blog.redjini.com/282�

QnA