在我看鸟个私房菜过程中,13章关于function的代码一个也运行不通,在仔细查找了原因后,才发现function在ubuntu下的格式和书上面的那种格式不一样。
鸟个私房菜代码:
#!/bin/bash
#program:
# show "Hello" from $1.... by using case.... esac
#History:
#2005/98/29 Vbird First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
function printit()
{
echo "Your choice is $1"
}
echo "This program will print your seletion!"
case $1 in
"one")
printit 1
;;
"two")
printit 2
;;
"three")
printit 3
;;
*)
echo "Usage $0 {one|two|three}"
;;
esac
在ubuntu下能运行的代码:
#!/bin/bash
#program:
# show "Hello" from $1.... by using case.... esac
#History:
#2005/98/29 Vbird First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
printit()
{
echo "Your choice is $1"
}
echo "This program will print your seletion!"
case $1 in
"one")
printit 1
;;
"two")
printit 2
;;
"three")
printit 3
;;
*)
echo "Usage $0 {one|two|three}"
;;
esac
就是去掉上面的function就对了
最后
以上就是阔达蜜蜂最近收集整理的关于ubuntu9下shell命令中的function的用法的全部内容,更多相关ubuntu9下shell命令中内容请搜索靠谱客的其他文章。
发表评论 取消回复