• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Linux程式设计-11.Shell Script(bash)--(2)教学例

发布: 2007-7-01 23:30 | 作者: admin | 来源: | 查看: 9次 | 进入软件测试论坛讨论

领测软件测试网 "Hello world" Shell Script
照传统程式教学例,这一节介绍Shell Script的"Hello World"如何撰写。



--------------------------------------------------------------------------------

#!/bin/sh
# Filename : hello
echo "Hello world!"

--------------------------------------------------------------------------------

大家应该会注意到第一行的"#!/bin/sh"。在UNIX下,所有的可执行Script,不管是那一种语言,其开头都是"#!",例如Perl是"#!/usr/bin/perl",tcl/tk是"#!/usr/bin/wish",看您要执行的Script程式位置在那里。您也可以用"#!/bin/bash"、"#!/bin/tcsh"等等,来指定使用特定的Shell。
echo是个bash的内建指令。



--------------------------------------------------------------------------------

接下来,执行hello这个script:
要执行一个Script的方式有很多种。



--------------------------------------------------------------------------------

第一种 : 将hello这个档案的权限设定为可执行。
[foxman@foxman bash]# chmod 755 hello
执行
[foxman@foxman bash]# ./hello
hello world



--------------------------------------------------------------------------------

第二种 : 使用bash内建指令"source"或"."。
[foxman@foxman bash]# source hello
hello world

[foxman@foxman bash]# . hello
hello world



--------------------------------------------------------------------------------

第三种 : 直接使用sh/bash/tcsh指令来执行。
[foxman@foxman bash]# sh hello
hello world

[foxman@foxman bash]# bash hello
hello world



--------------------------------------------------------------------------------

Bash执行选项

--------------------------------------------------------------------------------

-c string : 读取string来当命令。
-i : 互动介面。
-s : 由stdin读取命令。
- : 取消往後选项的读取。
-norc : 不要读~/.bashrc来执行。
-noprofile : 不要读/etc/profile、~/.bash_profile、~/.bash_login、~/.profile等等来执行。
-rcfile filename : 执行filename,而非~/.bashrc
-version : 显示版本。
-quiet : 启动时不要哩唆。
-login : 确保bash是个login shell。
-nobraceexpansion : 不要用curly brace expansion({}符号展开)。
-nolineediting : 不用readline来读取命令列。
-posix : 改采Posix 1003.2标准。

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网