#!/bin/bash source ~/.bashrc fun(){ echo "fun is begin.timeNum:$timeNum" local timeNum=$1 sleep $timeNum & wait #这个只等待wait前面sleep echo "fun is end.timeNum:$timeNum" } fun 10 & fun 20 & wait #如果fun里面没有wait,则整个脚本立刻退出,不会等待fun里面的sleep echo "all is ending"