Shell programming: Difference between revisions

From 탱이의 잡동사니
Jump to navigation Jump to search
No edit summary
Line 24: Line 24:
     echo $a
     echo $a
done
done
</source>
=== if ===
if 는 지정된 조건을 충족할 때만 실행된다.
<source lang=bash>
#!/bin/sh
if [ "$#" -gt 0 ]
then
    echo "There's Beans"
fi
if [ "$1" = "cool" ]
then
    echo "Cool Beans"
fi
</source>
</source>



Revision as of 09:30, 8 September 2015

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 />