Shell 编程
2016-06-28 15:52
393 查看
[root@localhost test]# cat test.sh #!/bin/bash #test
echo "hello, world." echo "hello, ${1}." [root@localhost test]# ./test.sh Jay hello, world. hello, Jay.
[root@localhost test]# echo $SHELL
/bin/bash
[root@localhost test]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost test]# ll
total 4
-rw-r--r--. 1 root root 0 Jun 27 23:34 test1.sh
-rwxrwxrwx. 1 root root 59 Jun 27 23:33 test.sh
[root@localhost test]# chmod u+x test1.sh
[root@localhost test]# ll
total 4
-rwxr--r--. 1 root root 0 Jun 27 23:34 test1.sh
-rwxrwxrwx. 1 root root 59 Jun 27 23:33 test.sh
[root@localhost test]#
#! //叫做”Shebang”或者”Sha-bang”,指明了执行这个脚本文件的解释程序
//没有#!这一行,那么它执行时会默认用当前Shell去解释这个脚本,(即:$SHELL环境变量)
//:#!之后的解释程序,需要写其绝对路径(如:#!/bin/bash),它是不会自动到$PATH中寻找解释器的
注释用#开始
•Linux给应用程序提供三种I/O通道
−标准输入(STDIN) – 缺省为键盘
−标准输出(STDOUT) – 缺省为终端窗口
−标准错误(STDERR) – 缺省为终端窗口
•标准输出和标准错误能被重定向到文件
−command operator filename
•支持操作包括:
−> 重定向标准输出到文件
−2> 重定向错误到文件
−&> 重定向所有输出到文件
•在重定向时, 缺省是覆盖文件内容.>>符号追加
重定向输出到文件-示例
[root@localhost test]# find /etc –name passwd > find.out 2>find.err [root@localhost test]# ll total 80 -rw-r--r--. 1 root root 85 Jun 28 07:34 find.err -rw-r--r--. 1 root root 63679 Jun 28 07:34 find.out
重定向标准输出给一个应用程序(管道)
[root@localhost ~]# cat install.log | less Installing libgcc-4.4.6-4.el6.x86_64 warning: libgcc-4.4.6-4.el6.x86_64: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY Installing fontpackages-filesystem-1.41-1.1.el6.noarch Installing xml-common-0.6.3-32.el6.noarch
结合输出和错误
相关文章推荐
- LINUX权限-bash: ./startup.sh: Permission denied
- 11.Shell数组
- shell编程基础
- Shell until循环
- Jmeter 中使用Beanshell来引用第三方jar包
- 【Linux】shell调用Java程序main方法通过crontab定时执行
- win10安装bash
- Shell while循环
- Shell for循环
- Shell case esac语句
- Shell if else语句
- shell printf命令:格式化输出语句
- 使用 PowerShell 自动登录 Azure
- 使用 PowerShell 自动登录 Azure
- 10.Shell操作符
- 使用 PowerShell 自动登录Azure
- ubuntu系统shell 中source: not found错误
- 使用PowerShell .Net获取电脑中的UUID
- shell编程初探
- Managing linux Shell Jobs