现在的位置: 首页 > 综合 > 正文

ubuntu9下shell命令中的function的用法

2013年03月05日 ⁄ 综合 ⁄ 共 872字 ⁄ 字号 评论关闭

在我看鸟个私房菜过程中,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就对了

抱歉!评论已关闭.