系统函数
basename 获取文件名,返回绝对路径最后/的部分
basename [pathname] [suffix]
basename [string] [suffix]
basename /root/shell/myShell.sh
myShell.sh
basename /root/shell/myShell.sh .sh #去掉.sh后缀
myShell
basename /root/shell
shell
dirname 获取路径,返回去除绝对路径最后部分的目录,与basename相反
dirname /root/shell/myShell.sh
/root/shell
dirname /root/shell
/root
自定义函数
[ function ] funname[()]
{
content;
[return int;]
}
#!/bin/bash
function getSum()
{
SUM=$[$1+$2]
ECHO "SUM=$SUM"
}
read -p "NUM1=" NUM1
read -p "NUM2=" NUM2
getSUM $NUM1 $NUM2