Shell Step by Step (1) —— Introduction
来源:互联网 发布:苍云正太捏脸数据 编辑:程序博客网 时间:2024/05/16 10:24
1. 查看当前用户(用户数)
root@kallen:~# who [ | wc -l]
root@kallen:~# who
kallen tty4 2015-01-16 10:46
kallen tty5 2015-01-16 10:47
kallen tty2 2015-01-16 10:42
kallen tty3 2015-01-16 10:42
root tty6 2015-01-16 10:58
kallen tty1 2015-01-15 13:10
kallen tty7 2015-01-15 12:52
root@kallen:~#
kallen tty4 2015-01-16 10:46
kallen tty5 2015-01-16 10:47
kallen tty2 2015-01-16 10:42
kallen tty3 2015-01-16 10:42
root tty6 2015-01-16 10:58
kallen tty1 2015-01-15 13:10
kallen tty7 2015-01-15 12:52
root@kallen:~#
root@kallen:~# who | wc -l
24
24
将管道l转化为独立的命令
root@kallen:~# cat > countUsers ---- 建立文件,使用cat复制终端输入
root@kallen:~# who | wc -l ---- 脚本内容
root@kallen:~# Ctrl + D ( end-of-file ) ---- end of file
root@kallen:~# Ctrl + D ( end-of-file ) ---- end of file
root@kallen:~# chmod +x countUsers ---- 让文件拥有执行权限
root@kallen:~# ./countUsers ---- 执行脚本
【附】wc命令
# Count Bytes
echo Testing one two three | wc -c print the byte counts (计算字节数)
# Count Rows
echo Testing one two three | wc -l print the character counts (计算字符数)
# Count Letters
echo Testing one two three | wc -w print the newline counts (计算行数)
2.脚本声明
#!/bin/bash
#
#!/bin/bash -
# - 表示没有shell选项,这是基于安全上的考虑,可避免某些欺骗式攻击(spoofing attack)
#
Shell的三种基本命令: 内建命令、Shell函数、外部命令
# 查看当前Shell类型
root@kallen:/# echo $SHELL
/bin/bash
/bin/bash
# Shell脚本执行方式
root@kallen:/# source shellFileroot@kallen:/# bash shellFile
root@kallen:/# ./shellFile (文件必须有可执行权限 chmod +x 或 chmod 755)
编写完脚本之后,你可以使用sh scriptname,[或者bash scriptname 来调用它.
(不推荐使用sh scriptname,因为这禁用了脚本从stdin 中读数据的功能.
使用sh scriptname 来调用脚本的时候将会关闭一些Bash 特定的扩展,脚本可能 因此而调用失败.)
更方便的方法是让脚本本身就具有可执行权限,通过chmod 命令可以修改.
比如:
chmod 555 scriptname (允许任何人都具有可读和执行权限)
或:
chmod +rx scriptname (允许任何人都具有可读和执行权限)
chmod u+rx scriptname (只给脚本的所有者可读和执行权限)
0 0
- Shell Step by Step (1) —— Introduction
- Shell Step by Step (2) —— Variable
- Shell Step by Step (3) —— Stdin & if
- Shell Step by Step (4) —— Cron & Echo
- Step by step——WinX开发入门教程-1
- 数据库设计 Step by Step (1)——扬帆启航
- 数据库设计 Step by Step (1)——扬帆启航
- 数据库设计 Step by Step (1)——扬帆启航
- 数据库设计 Step by Step (1)——扬帆启航
- EF框架step by step(1)—Database-First
- 深入MySQL源码—Step By Step
- iBATIS step by step (1)
- Git:step by step 1
- VPI step by step(1)
- step by step熟悉hbase shell
- Step-by-step Introduction to Delegates and Lambda Expressions
- Introduction to Microsoft Visual Studio(for beginners)step by step
- 【opengl】【step by step】一————三角形
- vlc android的编译及截图,录制视频等功能
- leetcode-------------ZigZag Conversion
- iOS动画进阶(三)图层几何学
- Android支付接入(八):Amazon亚马逊支付
- libxml2.dylb 添加后 引用不了<libxml/tree.h>
- Shell Step by Step (1) —— Introduction
- Jmeter集合点
- Java类设计
- 使用nginx实现js跨域
- ,2015道奇杜兰戈评析
- 三亚自由行,海鲜加工哪家强?
- activity中的所有动画效果
- iOS动画进阶(四)视觉效果
- hive 的配置项说明