linux-tutorial/codes/shell/示例脚本/脚本函数/默认退出状态码.sh

53 lines
505 B
Bash
Raw Normal View History

2019-05-10 11:17:57 +08:00
#!/bin/bash
# testing the exit status of a function
func1() {
2019-10-10 08:56:31 +08:00
echo "Trying to display a non-existent file"
ls -l badfile
2019-05-10 11:17:57 +08:00
}
#由于最后一条命令未执行成功返回的状态码非0
echo "testing the function"
func1
echo "The exit status is : $?"
func2() {
2019-10-10 08:56:31 +08:00
ls -l badfile
echo "Another test to display a non-existent file"
2019-05-10 11:17:57 +08:00
}
#由于最后一条命令echo执行成功返回的状态码为0
echo "Another test"
func2
echo "The exit status is : $?"