๊ด€๋ฆฌ ๋ฉ”๋‰ด

JiYoung Dev ๐Ÿ–ฅ

[Linux] ์‰˜ ๊ธฐ๋ณธ ๋ฌธ๋ฒ• (2023.08.09) ๋ณธ๋ฌธ

full stack/Linux

[Linux] ์‰˜ ๊ธฐ๋ณธ ๋ฌธ๋ฒ• (2023.08.09)

Shinjio 2023. 8. 9. 11:40

์ถœ๋ ฅ

  • echo  : ์ถœ๋ ฅ
  • printf : ์ถœ๋ ฅ (๊ฐœํ–‰ ์•ˆํ•จ)

 

 

๋ณ€์ˆ˜

  • ๋ณ€์ˆ˜์— ๊ฐ’ ํ• ๋‹น์€ ๋Œ€์ž…์—ฐ์‚ฐ์ž๋กœ
  • ๋ณ€์ˆ˜ ์‚ฌ์šฉ์‹œ์—๋Š” $

 

 

export

์ž๋ฐ”์—์„œ public๊ณผ ๋น„์Šทํ•œ ์—ญํ• 

 

 

Array

  • ๋ฐฐ์—ด์„ ์–ธ : ()
  • ํ•ด๋‹น ์ธ๋ฑ์Šค ๊ฐ’ ์‚ญ์ œ : unset
  • ํ•ด๋‹น ์ธ๋ฑ์Šค ๊ฐ’ ์ถ”๊ฐ€ : arr[idx] = ""

 

 

 

List

๋ฆฌ์ŠคํŠธ ์„ ์–ธ : ()

 

 

 

๋งค๊ฐœ๋ณ€์ˆ˜ 

 

 

expr

๋„์–ด์“ฐ์ง€ ์ฃผ์˜

 

 

ํ•จ์ˆ˜

function func(){

    ์‹คํ–‰๋ฌธ์ž

}

 

 

if๋ฌธ

 

#!/bin/bash
if [ 100 -eq 200] 
then
	echo "100๊ณผ 200์€ ๊ฐ™๋‹ค"
else 
	echo "100๊ณผ 200์€ ๋‹ค๋ฅด๋‹ค"
fi

exit 0

 

 

case๋ฌธ

 

#!/bin/bash
echo "๋ฆฌ๋ˆ…์Šค๊ฐ€ ์žฌ๋ฏธ์žˆ๋‚˜์š”? (yes/no)"
read answer
case $answer in
	yes | y | Y | Yes | YES)
		echo "๋‹คํ–‰์ž…๋‹ˆ๋‹ค"
		echo "๋”์šฑ ์—ด์‹ฌํžˆ ํ•˜์„ธ์š”^^";;
	n* | N*)
		echo "์•ˆํƒ€๊น๋„ค์š”.ใ… ใ… ";;
	*)
		echo "yes ์•„๋‹ˆ๋ฉด no๋งŒ ์ž…๋ ฅํ–ˆ์–ด์•ผ์ฃ "
		exit 1;;
esac

exit 0

 

for๋ฌธ

 

#!/bin/bash
for fname in $(ls *.sh)
do
	echo "--------$fname--------"
	head -3 $fname
done

exit 0

 

#!/bin/bash
echo "์ถœ๋ ฅํ•  ๋ณ„์˜ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”"
read num
for ((i=0 ; i < $num ; i++));
do
	for ((l=0 ; l <= i ; l++));
	do
		printf "*"
	done
	echo ""
done

str=\*
for ((i=1; i <= $num ; i++));
do
	echo "$str"
	str=$str\*
done

exit 0

 

while๋ฌธ

 

#!/bin/bash
hap=0
i=1
while [ $i -le 10 ]
do
	hap=`expr $hap + $i`
	i=`expr $i + 1`
done
echo "1๋ถ€ํ„ฐ 10๊นŒ์ง€์˜ ํ•ฉ : " $hap
exit 0

 

#!/bin/bash
echo "๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."
read mypass
while [ $mypass != "1234" ]
do
	echo "ํ‹€๋ ธ์Œ. ๋‹ค์‹œ ์ž…๋ ฅํ•˜์„ธ์š”."
	read mypass
done
echo "ํ†ต๊ณผ!"
exit 0

 

exit

๋ช…๋ น์–ด์˜ ์ข…๋ฃŒ