shell programming: the return value of the function

The return value of two forms

return 0-255 0 indicates success, typically 1-255 ------- represents a failure for determining

Returns a string ------------ generally echo to return the result of performing a

return.sh

#!/bin/bash
#

this_pid=$$

function nginxck

{
        ps -ef | grep nginx | grep -v grep | grep -v $this_pid | &> /dev/null
        if [ $? -eq 0 ];then
              return 0
        else
              return 1
        fi
}

nginxck && echo "nginx is running" || echo "nginx is stoped"

echo.sh

#!/bin/bash
#

function get_users

{
users=`cat /etc/passwd | cut -d ":" -f 1`
echo $users
}

user_list=`get_users`
index=1

for u in $user_list
do
echo "the $index user is : $u"
index=`expr $index + 1`
done

 

Guess you like

Origin www.cnblogs.com/soymilk2019/p/11730030.html