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的更多相关文章

  1. shell及脚本4——shell script

    一.格式 1.1 开头 必须以 "# !/bin/bash"  开头,告诉系统这是一个bash shell脚本.注意#与!中间有空格. 二.语法 2.1 数值运算 可以用decla ...

  2. shell script

    一.shell script的编写与执行 1.shell script 的编写中还需要用到下面的注意事项: a.命令的执行是从上到下,从左到右地分析与执行 b.命令.参数间的多个空白都会被忽略掉 c. ...

  3. (copy) Shell Script to Check Linux System Health

    source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...

  4. shell script练习

    执行脚本的几种方式: 1. sh a.sh 或者  bash a.sh  调用的是 /bin/bash 进程执行的,所以脚本不需要执行权限. 2. 直接使用绝对路径执行, /home/script/a ...

  5. 这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script

    这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script ##转载注明出处:http://www.cnblogs.com/wade-xu/p/4378224.html ...

  6. CentOS Linux下一个tomcat起停,查看日志的shell script

    CentOS 的tomcat安装目录:/usr/local/tomcat vi MyTomcatUitl.sh          创建文件chmod u+x MyTomcatUtil.sh   赋执行 ...

  7. 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 ...

  8. shell script入门

    从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的角度来看,Shell是用户与Linux操作系统沟通的桥梁.用户既可以输入命令执行,又可以利用 Shell脚本编程,完成更加复杂的操 ...

  9. shell script 的追踪与 debug

    shell script 的追踪与 debug scripts 在运行之前,最怕的就是出现语法错误的问题了!那么我们如何 debug 呢?有没有办法不需要透过直接运行该 scripts 就可以来判断是 ...

  10. 第十三章、学习 Shell Scripts 简单的 shell script 练习

    简单的 shell script 练习 简单范例 对谈式脚本:变量内容由使用者决定 [root@www scripts]# vi sh02.sh #!/bin/bash # Program: # Us ...

随机推荐

  1. Cardboard虚拟现实开发初步(二)

    Google Cardboard 虚拟现实眼镜开发初步(二) Cardboard SDK for Unity的使用 上一篇文章作为系列的开篇,主要是讲了一些虚拟现实的技术和原理,本篇就会带领大家去看一 ...

  2. C#如何给Listbox添加右键菜单

    1 拖一个ContextMenuStrip控件,然后可以直接在界面上编辑,也可以在FormLoad的时候动态添加 2 把这两个控件关联起来就可以实现listBox1的右键菜单跟ContextMenuS ...

  3. Android 4.4环境搭建——配置AVD模拟器

    AVD(Android Virtual Device)即Android模拟器,它是Android官方提供的一个能够执行Android程序的虚拟机,在执行Android程序之前,首先须要创建AVD模拟器 ...

  4. Hadoop之——HBASE结合MapReduce批量导入数据

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46463889 废话不多说.直接上代码,你懂得 package hbase; imp ...

  5. react 引入 百度地图API

    使用 Echarts 的地图的时候,发现报错,说 Bmap api is not loaded 百度地图API没有加载 乍一想,Echarts 用的也是 百度地图 啊,没有引入百度地图,还用个啥,当然 ...

  6. jeasyUI treegrid 的 reload 和 getChanges

    看上去,treegrid继承自datagrid,因此,datagrid有的,treegrid也会有. 比如说,getChanges,翻看那些网络教程,绝大多数都没提treegrid有这个东东.但是,t ...

  7. iOS开发——高级篇——线程同步、线程依赖、线程组

    前言 对于iOS开发中的网络请求模块,AFNet的使用应该是最熟悉不过了,但你是否把握了网络请求正确的完成时机?本篇文章涉及线程同步.线程依赖.线程组等专用名词的含义,若对上述名词认识模糊,可先进行查 ...

  8. js执行“按回车”的动作

    <textarea class="W_input" style="overflow: hidden; height: 23px;" node-type=& ...

  9. data-toggle data-target

    data-toggle https://stackoverflow.com/questions/30629974/how-does-the-data-toggle-attribute-work-wha ...

  10. 通过绑定ip地址可以暂时解决抢占ip问题

    以前设置的路由器密码都忘记了 admin重复,在工作上遇到了 一个去除str左右两边的空格换行符回车等 trim