- 리눅스 command들을 모아 놓은 ASCⅡ Text 파일
- 실행 퍼미션을 할당해야 실행 가능
vi test.sh
# test.sh 만들고 저장
echo "=========================="
date +%Y-%m-%d
echo "=========================="
df -h /
# 스크립트 파일 실행권한 부여
chmod +x test.sh
# 실행
./test.sh
- Bash shell script에서 특별히 의미가 정해진 기능
# | comment |
#!/bin/bash | 셔뱅.해시뱅.스크립트를 실행할 sub shell 이름 |
- Shell 구문은 기본 top-down 방식으로 해석해서 실행됨
- Sub shell
mkdir bin
cd bin
echo $PATH
PATH=$PATH:~/bin
echo $PATH
cat > sample.sh
#!/bin/bash
#: Title : Sample bash script
#: Date : 2022-01-01
#: Author : "abcd" <abcd@gmail.com>
#: Version : 1.0
#: Description : Print Hello World
echo "Today : $(date +%Y-%m-%d)"
echo "Hello, Linux World!"
chmod +x sample.sh
./sample.sh
cat > varUsage.sh
#!/bin/bash
#: Author : "abcd" <abcd@gmail.com>
#: Description : Print /var directory usage
echo "[ /var Directory ]"
echo "======================================"
date +%Y-%m-%d
echo "======================================"
du -sh /var 2> /dev/null
echo
chmod +x varUsage.sh
./varUsage.sh
- 문제풀이
cat > files.sh
#!/bin/bash
ls > /tmp/$(date +%Y%m%d).txt
chmod +x files.sh
./files.sh
- 출처 : 따배셸
5. Bash shell script란
728x90
반응형
'개발 > Linux' 카테고리의 다른 글
Bash Shell 입출력 (echo, read, printf) (0) | 2023.01.02 |
---|---|
Bash Shell Positional Parameters (위치 매개변수) (0) | 2023.01.02 |
Bash shell과 Rules(기능) (0) | 2022.12.30 |
Linux Shell이란, Bash shell과 변수 (0) | 2022.12.30 |
Linux 기본 명령어 (0) | 2022.12.27 |