shell-note-1-基础篇

1. Shell is a program written in C. It provides an interface for users to access to the service of os kernal. Windows Explorer is a typical graphic interface Shell.
2. Shell script is a script written for shell.
3. Bash: Bourne Again Shell, default for most Linux os
4. How to run Shell script?
(1) chmod +x ./fileName.sh # make it executable
./fileName.sh #"./" means search in current path
(2) /bin/sh fileName.sh # run interpreter
/bin/php test.php # not needed in file
5. type of variable
shell variable = environment + local
1) 局部变量: 在脚本或命令中定义,仅在当前shell实例中有效,其他shell启动的程序不能访问局部变量。
2) 环境变量: 所有的程序,包括shell启动的程序,都能访问环境变量。
6. 多行注释:可以把这一段要注释的代码用一对花括号括起来,定义成一个函数,没有地方调用这个函数,这块代码就不会执行,达到了和注释一样的效果。

7. Shell中的 test 命令用于检查某个条件是否成立,它可以进行数值、字符和文件三个方面的测试。可以添加test到这三种表达式之前。此处不用加[]

num1=100
num2=100
if test $num1 -eq $num2
then
echo num1 is equal to num2
fi

Shell还提供了与( -a )、或( -o )、非( ! )三个逻辑操作符用于将测试条件连接起来,其优先级为:"!"最高,"-a"次之,"-o"最低。

cd /bin
if test -e ./notFile -o -e ./bash
then
echo '有一个文件存在!'
else
echo '两个文件都不存在'
fi

8. 文件包含

. filename   # 注意点号(.)和文件名中间有一空格

source filename # 或者这样

被包含的文件 test1.sh 不需要可执行权限。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值