【鸟哥的私房菜摘录】SHELL脚本编程
来源:互联网 发布:淘宝网店可以注销吗 编辑:程序博客网 时间:2024/06/05 08:02
bash相关环境配置文件在~/.bashrc
标准模板范例如下:
#!/bin/bash# Program:# This program shows "Hello World!" in your screen.# History:# 2012.05.15 famousDT First release# main environment declarePATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/root/bin/:/home/famousDT/famousDT/scriptsexport PATH#++++++++++++++++++++++++++++++++++++++++++++++#user inputread -p "first name: " firstread -p "last name: " last#"-e" let '\' be usefullecho -e "\n Your full name is : $first $last"#++++++++++++++++++++++++++++++++++++++++++++++#creates three files, which named by user's#input and date command.read -p "input your filename: " fileuser#if fileuser not right, replace it by "filename"filename=${fileuser:-"filename"}date1=$(date --date='2 days ago' +%Y%m%d)date2=$(date --date='1 days ago' +%Y%m%d)date3=$(date +%Y%m%d)file1=${filename}${date1}file2=${filename}${date2}file3=${filename}${date3}touch "$file1"touch "$file2"touch "$file3"#used for "$?" as return value for callerexit 0
数值运算,只能做整数计算
#++++++++++++++++++++++++++++++++++++++++++++++#user inputs 2 integer numbers a, b, return a*bread -p "input first: " firstread -p "input second: " secondtotal=$(($first * $second));echo -e "\nThe result of $first * $second = $total"
累加计算1+2+……100
#++++++++++++++++++++++++++++++++++++++++++++++s=0end=100for ((i=1;i<=$end;i=i+1))dos=$(($s+$i))doneecho $s
直接执行shell脚本是在子进程中执行的,如果用source来执行脚本,则在父进程中执行,在子进程中设置的变量在父进程中有效。这也是为什么不用注销系统而要让某些写入~/.bashrc的设置生效,需要使用source ~/.bashrc而不能用bash ~/.bashrc
- 【鸟哥的私房菜摘录】SHELL脚本编程
- 鸟哥私房菜shell script的脚本学习
- 鸟哥私房菜shell和shell脚本总结(仅自己看)
- 鸟哥的私房菜--第五章Linux的权限与目录配置--摘录,笔记
- 鸟哥的linux私房菜之WWW服务器--摘录
- Linux vi编辑器(鸟哥的Linux私房菜摘录)
- linux基础学习-shell脚本学习(鸟哥私房菜)
- Shell脚本之鸟哥私房菜第13章sh11
- [Linux]鸟哥的linux私房菜-shell RE
- 鸟哥的Linux私房菜10.19 Shell Scripts
- Shell 中的变量(鸟哥的linux私房菜)
- 鸟哥的 Linux 私房菜 -- 学习 bash shell
- 鸟哥的 Linux 私房菜 -- 学习 bash shell
- 鸟哥的 Linux 私房菜 -- 学习 bash shell
- 学习shell笔记------------鸟哥的私房菜
- 学习使用shell script 笔记--------鸟哥的私房菜
- 鸟哥的私房菜:Bash shell(六)-管道命令
- 鸟哥的Linux私房菜学习笔记--shell入门
- 冒泡排序
- 诸事衫式
- 三种东西永远不要放到数据库里
- 使用sql语句建立与删除链接服务器及执行数据库操作
- Eclipse中安装反编译插件jadclipse
- 【鸟哥的私房菜摘录】SHELL脚本编程
- 建表时的常见约束
- 《重构》要点列表
- 网站DDOS攻击防护实战老男孩经验心得分享
- eclipse插件项目中的后缀名为.exsd文件的作用
- OpenGL 环绕和绘制三角形
- PS课堂笔记(截图)
- hdU 2222 Keywords Search(AC自动机)
- Which responsive images solution should you use?