본문으로 건너뛰기
0%
약 1분 (352 단어) ko

Bash set Utility Guide

Categories TechSavvy Bash
Tags #TechSavvy #ProgrammingLanguage #Bash

set

set -e

When set -e is executed within a script, the shell environment will stop executing subsequent commands if any script command fails with an error.

This is super handy when you want your script to fail fast instead of continuing with potentially broken state. Think of it as your script’s safety net!

exit code

Generally in Unix systems, 0 means success, and 1255 are recognized as error codes. The recognized range is 0255 (8-bit, not 16-bit as originally stated). You can check the result value with $?.

$ cat test.sh
echo "hello"
exit 100
$ sh test.sh
hello
$ echo $?
100

Pretty straightforward, right? The script says “hello” and then exits with code 100, which you can immediately check with $?.

set -x

When set -x is executed within a script, the shell environment will show all shell commands in verbose mode.

This is basically your debugging best friend! It’ll print out every command before executing it, so you can see exactly what’s happening step by step. Super useful when your script isn’t behaving the way you expect.

Appendix. References

Share this article

Found this helpful? Share it with your network

Join the Discussion

Share your thoughts and connect with other readers

댓글

GitHub 계정으로 로그인하여 댓글을 남겨보세요. 건설적인 의견과 질문을 환영합니다!

댓글을 불러오는 중...