Bash 스크립트 root로 실행했는지 확인

Jmnote (토론 | 기여)님의 2021년 10월 18일 (월) 10:38 판 (→‎참고)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

How to check if running as root in a bash script
Bash 스크립트 root로 실행했는지 확인
if [ $(id -u) -ne 0 ]; then
	echo "Please run as root."
	exit
fi
echo "Hello, root!"
jmnote@zetawiki:~$ sh need_root.sh 
Please run as root.
jmnote@zetawiki:~$ sudo sh need_root.sh 
Hello, root!

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}