Shell script之How to write
Write shell script:
1) Editor like vi or mcedi
2) Set execute permission for your script
chmod permission your-script-name
- $ chmod +x your-script-name
- $ chmod 755 your-script-name
This will set read write execute(7) permission for owner, for group and other permission is read and execute only(5).
3) Execute script
bash your-script-name
sh your-script-name
./your-script-name
In the last syntax ./ means current directory, But only . (dot) means execute given command file in current shell without starting the new copy of shell.
- $ . foo
4) Practice
- $ vi first
- #
- # My first shell script
- #
- clear
- echo "Knowledge is Power"
- $ vi ginfo
- 2 #
- 3 #
- 4 # Script to print user information who currently login , current date & time
- 5 #
- clear
- echo "Hello $USER"
- echo "Today is \c ";date
- echo "Number of user login : \c" ; who | wc -l
- echo "Calendar"
- cal
- exit 0
5) Feng - quickly go to specific directory by shell scripts
- 1 #!/bin/bash
- 2 # ----------------------------------------------------------------------------
- 3 # quickly go to software development directory
- 4 # ----------------------------------------------------------------------------
- if [ $# -eq ]; then
- cd '01_Project/02_Projrct_Name/02_DIGITAL/01_src/software/embedded'
- 8 # list all the software development directory
- ls
fi
then in your Linux terminal enter
- # dot(.) can execute command file at current directory
- . software.sh
Shell script之How to write的更多相关文章
- shell及脚本4——shell script
一.格式 1.1 开头 必须以 "# !/bin/bash" 开头,告诉系统这是一个bash shell脚本.注意#与!中间有空格. 二.语法 2.1 数值运算 可以用decla ...
- shell script
一.shell script的编写与执行 1.shell script 的编写中还需要用到下面的注意事项: a.命令的执行是从上到下,从左到右地分析与执行 b.命令.参数间的多个空白都会被忽略掉 c. ...
- (copy) Shell Script to Check Linux System Health
source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...
- shell script练习
执行脚本的几种方式: 1. sh a.sh 或者 bash a.sh 调用的是 /bin/bash 进程执行的,所以脚本不需要执行权限. 2. 直接使用绝对路径执行, /home/script/a ...
- 这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script
这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script ##转载注明出处:http://www.cnblogs.com/wade-xu/p/4378224.html ...
- CentOS Linux下一个tomcat起停,查看日志的shell script
CentOS 的tomcat安装目录:/usr/local/tomcat vi MyTomcatUitl.sh 创建文件chmod u+x MyTomcatUtil.sh 赋执行 ...
- Shell script for logging cpu and memory usage of a Linux process
Shell script for logging cpu and memory usage of a Linux process http://www.unix.com/shell-programmi ...
- shell script入门
从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的角度来看,Shell是用户与Linux操作系统沟通的桥梁.用户既可以输入命令执行,又可以利用 Shell脚本编程,完成更加复杂的操 ...
- shell script 的追踪与 debug
shell script 的追踪与 debug scripts 在运行之前,最怕的就是出现语法错误的问题了!那么我们如何 debug 呢?有没有办法不需要透过直接运行该 scripts 就可以来判断是 ...
- 第十三章、学习 Shell Scripts 简单的 shell script 练习
简单的 shell script 练习 简单范例 对谈式脚本:变量内容由使用者决定 [root@www scripts]# vi sh02.sh #!/bin/bash # Program: # Us ...
随机推荐
- 【Web API系列教程】1.1 — ASP.NET Web API入门
前言 HTTP不仅仅服务于web页面.同一时候也是构建暴露服务和数据的API的强大平台.HTTP有着简单.灵活和无处不在的特点.你能想到的差点儿全部平台都包括有一个HTTP库.所以HTTP服务能够遍及 ...
- Android自己主动提示文本框(AutoCompleteTextView)
自己主动提示文本框(AutoCompleteTextView)能够加强用户体验,缩短用户的输入时间(百度的搜索框就是这个效果). 首先.在xml中定义AutoCompleteTextView控件: a ...
- SSLStrip 终极版 —— location 瞒天过海
之前介绍了 HTTPS 前端劫持 的方案,尽管非常有趣.然而现实却并不理想. 其唯一.也是最大的缺陷.就是无法阻止脚本跳转.若是没有这个缺陷,那就非常完美了 -- 当然也就没有必要写这篇文章了. 说究 ...
- java中关于'&&'、'||'混合运算优先级问题小结
package com.per.sdg.operator; /** * 结论:先进行'&&'运算,在进行'||'运算 * @author sundg * */ public class ...
- 【Android】使用 SwipeRefreshLayout 实现下拉刷新
今天在codepath 上看到一个开源项目 [点击查看]使用到了 SwipeRefreshLayout 实现了下拉刷新,但演示样例并不完整,于是自己就动手写了下.之前看到郭霖的博客上也有介绍下拉刷新, ...
- 并不对劲的st表
对于带修改的区间求和能做到O(n log n)预处理,O(log n)查询:而不带修改的可以做到O(n)预处理,O(1)查询.那么不带修改的区间最值能做到O(1)查询吗? 区间最值有这样一个性质:对于 ...
- git 查看、切换用户
查看命令: 查看用户名: git config user.name 查看用户邮箱: git config user.email 修改命令: 修改用户名: git config --global use ...
- 使用IntelliJ IDEA 创建Maven项目(入门)
一. 下载Maven 下载地址:http://maven.apache.org/download.cgi tar.gz压缩格式用于unix操作系统,而zip用于windows的操作系统,但在windo ...
- bzoj 2726: [SDOI2012]任务安排【cdq+斜率优化】
cdq复健.jpg 首先列个n方递推,设sf是f的前缀和,st是t的前缀和: \[ f[i]=min(f[j]+s*(sf[n]-sf[j])+st[i]*(sf[i]-sf[j])) \] 然后移项 ...
- P1606 [USACO07FEB]荷叶塘Lilypad Pond(最短路计数)
P1606 [USACO07FEB]荷叶塘Lilypad Pond 题目描述 FJ has installed a beautiful pond for his cows' aesthetic enj ...