linuxshell 读书笔记 (unix shell 第三版)
来源:互联网 发布:excel数据录入程序 编辑:程序博客网 时间:2024/05/15 23:43
把一些简单的命令放入文件中 如 cat echo_script
#echo demo
echo the current data and time is:
date
echo
echo the number of users on the system is:
who|wc -l
echo
echo your current working directory is :
pwd
修改echo_script文件属性 使其可执行 chmod 755 echo_script
执行这个脚本 ./echo_script
在当前目录上创建两个文件夹 mkdir -p xep/work
[xep@localhost ~]$ cat variable_script
#variable demo
my_bin="/home/xep/xep/work"
number=99
cd $my_bin
pwd
echo there are $number beer on the wall
command=sort
cd ../..
$command test1 2>null
修改脚本属性 执行后看结果
cat cmd_script
#put command to variable
cmd=sort
para=-r
file=test.123
运行时 shell会在执行命令前把执行的命令和参数进行替换
对于空变量的解释 echo :$xxxxx:
x=*
echo $x, '$x', "$x"--当前目录下文件名,'$x',*
mv $file ${file}_1 --将文件名重命名为之前文件名_1
算术扩展 $(( )) --不支持带小数的计算
echo $((i+10))
echo result=(($i>0 && $j>0)) --真返回1否则为0
输入命令查看结果 --不支持带小数的计算
expr 2 + 3 expr 2+3 expr 2 * 3 expr 2 \* 3
bc 命令 带小数计算
[xep@localhost ~]$ lines=one'
> two
> 'three
[xep@localhost ~]$ echo $lines --最后输入的'表示换行
one two three
[xep@localhost ~]$ lines=one\
> \two
[xep@localhost ~]$ echo $lines --与'的作用相似
onetwo
[xep@localhost ~]$ echo your current working directory is `pwd`
your current working directory is /home/xep
--shell将所有``中命令的标准输入放在当前位置 所有用$()的地方可换为``
[xep@localhost ~]$ cat args_script
echo $# arguments passed
echo arg 1=:$1: arg 2=:$2: arg 3=:$3:
输入命令查看结果
./args_script $(cat file) --将file中的内容做为参数 $# 输入参数的个数
./args_script t* --将当前目录中t开头的文件为参数
[xep@localhost ~]$ cat args2_script
echo there are $# parameter passed
echo there are $*
输入命令查看结果
./args2_script $(cat file) --将file中的内容做为参数 $* 所有输入参数的内容
./args2_script t* --将当前目录中t开头的文件为参数
[xep@localhost ~]$ cat args3_script
declare directory=/home/xep
file=phonebook
grep "$1" ${directory}/$file
输入命令查看结果
#echo demo
echo the current data and time is:
date
echo
echo the number of users on the system is:
who|wc -l
echo
echo your current working directory is :
pwd
修改echo_script文件属性 使其可执行 chmod 755 echo_script
执行这个脚本 ./echo_script
在当前目录上创建两个文件夹 mkdir -p xep/work
[xep@localhost ~]$ cat variable_script
#variable demo
my_bin="/home/xep/xep/work"
number=99
cd $my_bin
pwd
echo there are $number beer on the wall
command=sort
cd ../..
$command test1 2>null
修改脚本属性 执行后看结果
cat cmd_script
#put command to variable
cmd=sort
para=-r
file=test.123
运行时 shell会在执行命令前把执行的命令和参数进行替换
对于空变量的解释 echo :$xxxxx:
x=*
echo $x, '$x', "$x"--当前目录下文件名,'$x',*
mv $file ${file}_1 --将文件名重命名为之前文件名_1
算术扩展 $(( )) --不支持带小数的计算
echo $((i+10))
echo result=(($i>0 && $j>0)) --真返回1否则为0
输入命令查看结果 --不支持带小数的计算
expr 2 + 3 expr 2+3 expr 2 * 3 expr 2 \* 3
bc 命令 带小数计算
[xep@localhost ~]$ lines=one'
> two
> 'three
[xep@localhost ~]$ echo $lines --最后输入的'表示换行
one two three
[xep@localhost ~]$ lines=one\
> \two
[xep@localhost ~]$ echo $lines --与'的作用相似
onetwo
[xep@localhost ~]$ echo your current working directory is `pwd`
your current working directory is /home/xep
--shell将所有``中命令的标准输入放在当前位置 所有用$()的地方可换为``
[xep@localhost ~]$ cat args_script
echo $# arguments passed
echo arg 1=:$1: arg 2=:$2: arg 3=:$3:
输入命令查看结果
./args_script $(cat file) --将file中的内容做为参数 $# 输入参数的个数
./args_script t* --将当前目录中t开头的文件为参数
[xep@localhost ~]$ cat args2_script
echo there are $# parameter passed
echo there are $*
输入命令查看结果
./args2_script $(cat file) --将file中的内容做为参数 $* 所有输入参数的内容
./args2_script t* --将当前目录中t开头的文件为参数
[xep@localhost ~]$ cat args3_script
declare directory=/home/xep
file=phonebook
grep "$1" ${directory}/$file
输入命令查看结果
./args3_script "Alica chebba" --如果不在"$1"外加双引号 再试试
- linuxshell 读书笔记 (unix shell 第三版)
- linuxshell 读书笔记二 (unix shell 第三版)
- linuxshell 读书笔记三 (unix shell 第三版)
- linuxshell 读书笔记四 (unix shell 第三版)
- linuxshell 读书笔记五 (unix shell 第三版)
- linuxshell 读书笔记六 (unix shell 第三版)
- UNIX Shell 编程读书笔记
- Unix Shell编程(第三版)学习笔记
- linuxshell 脚本攻略读书笔记
- 读书笔记-APUE第三版-(1)UNIX系统概述
- 读书笔记-APUE第三版-(2)UNIX标准和实现
- Unix® Shell Programming读书笔记1
- Unix® Shell Programming读书笔记2
- Unix® Shell Programming读书笔记3
- Unix® Shell Programming读书笔记4(END)
- unix shell编程(读书笔记1):基础回顾
- 读书笔记-LinuxShell编程与服务器管理-part1
- WindowsBatch与LinuxShell比较[shell循环实例]
- linux c libcurl的简单使用
- 阻塞和非阻塞
- 使用UDL创建数据库连接
- Selenium的getXpathCount方法的实际问题解决
- linux多线程编程(实例)
- linuxshell 读书笔记 (unix shell 第三版)
- 软件人员需把握物质能量信息三基元
- java对象池ObjectPool
- IIS配置需要登陆才能访问的目录权限
- Oracle 存储过程存取图片
- 用sqlCommandBuilder批量更新
- j2me Socket编程常用服务器和客户端编写结构
- 【备忘录-网络】常见HTTP状态值
- fcitx切换半角/全角,显示状态条