我是靠谱客的博主 阔达蜜蜂,这篇文章主要介绍ubuntu9下shell命令中的function的用法,现在分享给大家,希望可以做个参考。

在我看鸟个私房菜过程中,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命令中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部