-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.shell_programming.sh
More file actions
59 lines (52 loc) · 1.01 KB
/
Copy path3.shell_programming.sh
File metadata and controls
59 lines (52 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 쉘 스크립트 작성 : 반드시 확장자 .sh
touch myscript.sh
# 스크립트문 nano편집기에서 작성
nano myscript.sh
# 스크립트 실행 : ./를 붙여줘야함에 유의.
./myscript.sh
# if문
if [ 1 -gt 2 ]; then
echo "hello world1"
else
echo "hello world2"
fi
# if문과 변수, 파일(-f), 디렉토리(-d) 존재여부 확인
file_name="test.txt"
if [ -f "$file_name" ]; then
echo "$file_name file exists"
else
echo "$file_name file does not exist"
fi
# for문
for a in {1..100};
do
echo "hello world$a"
done
# for문과 count값
count=0
for a in {1..100}
do
((count++))
done
echo "count value is $count "
# for문과 파일/디렉토리 목록조회
for a in *
do
echo "$a"
done
file_count=0
dir_count=0
other_count=0
for a in *
do
if [ -f "$a" ]; then
((file_count++))
elif [ -d "$a"]
((dir_count++))
else
((other count++))
fi
done
echo "file count is $file_count"
echo "dir count is $dir_count"
echo "other count is $other_count"