linux学习shell篇

"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这个档案的权限设定为可执行。 
[root@redhat proshell]# chmod 755 hello 
执行 
[root@redhat proshell]# ./hello 
hello world 

 

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

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

 

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

第三种 : 直接使用sh/bash/tcsh指令来执行。 
[root@redhat proshell]# sh hello 
hello world 
或 
[root@redhat proshell]# 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标准。 

(参考:http://www.fanqiang.com)
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值