shell编程入门开始:
来源:互联网 发布:mac第一次充电多久 编辑:程序博客网 时间:2024/06/05 04:50
初衷: 通过shell脚本,一键搞定 文件创建,版本大包,文件上传,等一系列批处理指令,以前用java比较多, shell编程也至少需要的时候再到网上查看一下, 今天稍微系统看了一下,简单总结一下吧: 想法是,java中常用的功能 如何通过 shell 去实现:
#!/bin/bash#Define a functionfunction loopFile(){ count=0; echo ${count};}loopFile#include params Functionfunction add(){sum_1=$1;sum_2=$2;echo ${sum_1}echo ${sum_2}echo $[${sum_1}*${sum_2}];}add 1 2for((i=0;i<10;i++ ));doecho ${i}donea=(1 2 3 4 5)echo ${#a[*]} # #代表获取数组长度echo ${a[1]} # 获取指定index对应的值echo ${a[*]} # 获取数组中所有值a[1]=100 # 赋值echo ${a[*]}echo ${a[*]:0:3} #分片操作 获取 下标 0-3的值a=(1,2,3,4,5)echo ${a[*]/3/500} #将下表为3的值替换为 500a=(1 2 3 4 5) #for循环遍历数组for i in ${a}doecho ${a[i]}doneString="helloWorld" #遍历字符串中的每一个字符for((i=0;i<${#String};i++))doecho ${String:i:1}doneFile="/debuger.sh" #for循环遍历文件内容: < 将文件内容重定向到变量中Current=$(pwd)FilePath=${Current}${File}echo ${FilePath}for line in $(<${FilePath})doecho ${line}doneFile="/debuger.sh" #for循环遍历文件内容: > 写文件 ; < 读文件Current=$(pwd)FilePath=${Current}${File}cat ${FilePath} | while read line;doecho ${line}doneFile="/debuger.sh" #for循环遍历文件内容: > 写文件 ; < 读文件Current=$(pwd)FilePath=${Current}${File}cat ${FilePath} | while read line;doecho ${line}doneFile="/text.txt" # -e 允许一行执行多行命令 d参数 删除读入缓冲区对应行字符File2="/text1.txt"Current=$(pwd)FilePath=${Current}${File}FilePath2=${Current}${File2}if [ -f ${FilePath2} ]; then rm ${FilePath2}fised -e '1,2d' ${FilePath} > ${FilePath2} #删除第一行到第二行 并重定向到新创建的文件File="/text.txt" # s 替换指定输入流中第一次出现的字符为指定字符 并指定到输出文件File2="/text1.txt"Current=$(pwd)FilePath=${Current}${File}FilePath2=${Current}${File2}if [ -f ${FilePath2} ]; then rm ${FilePath2}fised -e 's/begin/tt/g' ${FilePath} > ${FilePath2}
0 0
- shell编程入门开始:
- 开始学习Shell编程
- 开始Shell编程
- TCSH shell 编程入门
- TCSH shell 编程入门
- csh shell编程入门
- TCSH shell编程入门
- shell编程快速入门
- shell编程入门
- shell编程:入门例子
- Linux Shell编程入门
- linux Shell编程入门
- shell编程入门指南
- Linux Shell编程入门
- Shell扩展编程入门
- 【原创】shell编程入门
- Linux Shell编程入门
- Shell编程入门
- Memcached
- Java基础之-IO中的字节流
- 随机数
- 关于 tomcat 与X-Frame-Options
- linphone-ErrorInfoImpl文件对应的JNI层文件分析
- shell编程入门开始:
- HDOJ 2094 产生冠军
- winfrom—DataGridView导出Excel,并根据内容自动调整列宽
- 还在羡慕微信/微博的图片处理?-android酷炫图片处理(下)
- Linux终端命令查看自己的公网地址
- Android 地区和日期选择器(附源码)
- poj 2774 Long Long Message 后缀数组
- 动态注入技术
- 关于this指针和闭包