Shell programming

From 탱이의 잡동사니
Revision as of 09:30, 8 September 2015 by Pchero (talk | contribs) (→‎Statements)
Jump to navigation Jump to search

Overview

리눅스 쉘 프로그래밍 정리

Statements

for

<source lang=bash>

  1. !/bin/sh

for var in A B C do

   echo "var is $var"

done </source>

while

while 은 조건이 만족하는 동안 루프를 반복한다. <source lang=bash>

  1. !/bin/sh

a=0 while [ $a -lt 10 ] do

   a=`expr $a + 1`
   echo $a

done </source>

if

if 는 지정된 조건을 충족할 때만 실행된다. <source lang=bash>

  1. !/bin/sh

if [ "$#" -gt 0 ] then

   echo "There's Beans"

fi

if [ "$1" = "cool" ] then

   echo "Cool Beans"

fi </source>

See also

References

<references />