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. Kafka单机Windows环境搭建

    Kafka单机Windows环境搭建 1,安装jdk1.8:安装目录不能有中文空格: 2,下载zookeeper,https://mirrors.cnnic.cn/apache/zookeeper/z ...

  2. centos7 禁止 root ssh login

    CentOS 7 默认容许任何帐号透过 ssh 登入,包括 root 和一般帐号,为了不让 root 帐号被黑客暴力入侵,我们必须禁止 root 帐号的 ssh 功能,事实上 root 也没有必要 s ...

  3. create-react-app 引入 antd 及 解决 antd 样式无法显示的bug

    方案一: npm run eject 暴露所有内建的配置 安装组件库 yarn add antd babel-plugin-import 根目录下新建.roadhogrc文件(别忘了前面的点,这是ro ...

  4. EEPlat的控制器概念

    控制器是EEPlat平台界面层部分的核心概念.平台中界面展示都是通过平台的各种控制器综合控制输出的. EEPlat平台的界面层模型採用了HMVC模式.HMVC模式的採用使得EEPlat平台界面层可以实 ...

  5. mybatis之if else语句

    最近项目中遇到一个相同表设计,但是表名不同的sql语句操作. 在遇到这样的情况时候可以用一下方式: <choose> <when test=""> //.. ...

  6. Google's Hybrid Approach to Research

    文档地址:戳我 总结: (i) aims to generate scientific and engineering advances in fields of import to Google, ...

  7. ldd LD_TRACE_LOADED_OBJECTS

    1 该环境变量设置为1的话,只会打印所执行的程序的依赖,即所依赖的动态链接库

  8. wxpc

  9. Linux/Android——usb触摸屏驱动 - usbtouchscreen (一)【转】

    本文转载自:http://blog.csdn.net/jscese/article/details/41827495 最近需要往TV上装一个触摸屏设备,现在比较常见的就是使用usb接口的触摸框,适用于 ...

  10. mac 下idea光标问题

    可以使用 fn + i 解决此问题