shell函数返回字符串用echo
shell中要返回字符串不能使用return,用echo
# cat test.sh
#!/bin/bash
logpath="/data/log/file1.log"
getpath() {
echo $logpath
}
case "$1" in
getpath)
getpath
;;
*)
echo $"Usage: $0 {getpath}"
esac
运行:
# ./test.sh getpath /data/log/file1.log
# a=`bash test.sh getpath` # echo $a /data/log/file1.log

共有 0 条评论