下面示例判断 $spec 变量所含的字符串是否以 '/' 开头,如果 $spec 开头不是 '/' ,那么 ${spec#/} 返回自己本身的值,if 测试条件为真。
# ${spec#/} 去掉开头的 '/',这里的作用是判断 $spec 路径是否是绝对路径 if [ "$spec" = "${spec#/}" ]; then spec="`pwd`/$spec" fi