shell作业(一)

简介: shell作业(一)

1.编写函数,实现打印绿色OK和红色FAILED判断是否有参数,存在为Ok,不存在为FAILED

result_test(){
  if [ $# -eq 0 ]; then
    echo -e "\033[31mFAILED\033[0m"
  else
    echo -e "\033[32mOK\033[0m"
  fi
}
result_test [a, b, c, d]

2.编写函数,实现判断是否无位置参数,如无参数,提示错误

check_args(){
  if [ $# -eq 0 ]; then
    echo "error!!!"
    return 1
  else 
    echo $@
  fi
}
check_args $*

3.编写函数实现两个数字做为参数,返回最大值

max(){
  if [ "$1" -gt "$2" ]; then
    echo "$1"
  else
    echo "$2"
  fi
}
max $1 $2


相关文章
|
2月前
|
Shell
shell作业项目留存代码
shell作业项目留存代码
29 1
|
11月前
|
Shell
shell作业三
shell作业三
|
11月前
|
Shell
shell作业(二)
shell作业(二)