Linux Shell进化简史

发表于:2011-12-26 10:12

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:张志平 译    来源:51Testing软件测试网采编

分享:

  Korn Shell在许多操作系统上都是可用的,这些系统包括IBM AIX and HP-UX。Korn Shell努力支持Portable Operating System Interface for UNIX(POSIX)Shell语言的标准。

  我们来看一下在Korn Shell中统计可执行文件数目脚本的例子:

  代码2:在Korn Shell中统计可执行文件的数目

  1. #!/usr/bin/ksh 
  2. # find all executables 
  3.  
  4. count=0 
  5.  
  6. # Test arguments 
  7. if [ $# -ne 1 ] ; then 
  8.   echo "Usage is $0 <dir>" 
  9.   exit 1 
  10. fi 
  11.  
  12. # Ensure argument is a directory 
  13. if [ ! -d  "$1" ] ; then 
  14.   echo "$1 is not a directory." 
  15.   exit 1 
  16. fi 
  17.  
  18. # Iterate the directory, emit executable files 
  19. for filename in "$1"/* 
  20. do 
  21.   if [ -x "$filename" ] ; then 
  22.     echo $filename 
  23.     count=$((count+1)) 
  24.   fi 
  25. done 
  26.  
  27. echo 
  28. echo "$count executable files found." 
  29.  
  30. exit 0

  Bourne-Again Shell

  Bourne-Again Shell,即bash,是一个开源的GNU项目,旨在替换Bourne Shell。Bourne-Again Shell由Brian Fox开发,现在已经成为最流行的Shell之一,被广泛应用在Linux、Darwin、Windows和Cygwin之上。

  除了支持脚本的向后兼容性,bash还吸收了Korn Shell和C Shell的一些特性。例如,命令历史记录,命令行编辑,目录堆栈,很多实用的环境变量,命令行自动完成,等等。

  Bash继续发展了一些新的特性,如支持正则表达式和关联数组。

  虽然一些特性是bash独有的,但我们仍然可以编写与其他脚本语言相兼容的脚本。下面是在bash中统计可执行文件数目的脚本示例。

  代码3:在Bourne-Again Shell中统计可执行文件的数目

  1. #!/bin/bash 
  2. # find all executables 
  3.  
  4. count=0 
  5.  
  6. # Test arguments 
  7. if [ $# -ne 1 ] ; then 
  8.   echo "Usage is $0 <dir>" 
  9.   exit 1 
  10. fi 
  11.  
  12. # Ensure argument is a directory 
  13. if [ ! -d  "$1" ] ; then 
  14.   echo "$1 is not a directory." 
  15.   exit 1 
  16. fi 
  17.  
  18. # Iterate the directory, emit executable files 
  19. for filename in "$1"/* 
  20. do 
  21.   if [ -x "$filename" ] ; then 
  22.     echo $filename 
  23.     count=$((count+1)) 
  24.   fi 
  25. done 
  26.  
  27. echo 
  28. echo "$count executable files found." 
  29.  
  30. exit 0

  这些Shell之间的一个关键区别是它们使用了不同的授权。Bash是一个GNU项目,遵循GPL授权,而C Shell则遵循了BSD许可,Korn Shell则遵循了通用公共许可证。

  早期Shell的许多理念和接口在35年之后依然保持不变,这对其作者是一个巨大的肯定。任何一个行业都在不断重塑自我,Shell也在发生着历史的变迁。尽管许多新的Shell被开发出来,但Bourne Shell及其后继者依然是现在的首选。

33/3<123
精选软件测试好文,快来阅读吧~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号