(1).bash(或sh) [脚本的相对路径或绝对路径]

[xf@xuexi ~]$ cat a.sh
#!/bin/bash
echo "hello world!"
[xf@xuexi ~]$ bash a.sh
hello world!
[xf@xuexi ~]$ which bash
/usr/bin/bash
[xf@xuexi ~]$ sh a.sh
hello world!
[xf@xuexi ~]$ which sh
/usr/bin/sh
[xf@xuexi ~]$ ll /usr/bin/sh
lrwxrwxrwx. 1 root root 4 4月 5 22:07 /usr/bin/sh -> bash

  可以看到sh命令实际指向的是bash命令,sh只是bash的一个软链接

(2).source(或.) [脚本的相对路径或绝对路径]

  .(点)是等同于source的,最常见的使用是在重新加载环境变量时。

[xf@xuexi ~]# source a.sh
hello world!
[xf@xuexi ~]# . a.sh
hello world!

(3).sh < [脚本名称]或者cat [脚本名称] | sh(或bash)

[xf@xuexi ~]# sh < a.sh
hello world!
[xf@xuexi ~]# cat a.sh | sh
hello world!

(4).脚本的相对路径或绝对路径,使用该方法,脚本必须拥有执行权限

[xf@xuexi ~]$ chmod +x a.sh
[xf@xuexi ~]$ ./a.sh
hello world!
[xf@xuexi ~]$ /home/xf/a.sh
hello world!

  

Shell脚本执行的四种方法的更多相关文章

  1. Linux中执行shell脚本命令的4种方法总结

    bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本所在 ...

  2. 【Shell脚本】运行shell脚本文件的几种方法与区别

    Shell脚本不同的运行方式会对当前Shell设置或者运行结果有所不同. 假设现在有一个脚本名为display_shell_script_args.sh,其内容如下: #!/home/pyf/bin/ ...

  3. SHELL脚本运行的几种方法以及区别

    #1 给脚本加上执行权限chmod u+x a.sh, 而后就可以直接用全路径来执行脚本了,比如当前文件夹下用./a.sh,如果如果脚本所在目录在PATH环境变量之中, 则直接用a.sh即可(这和运行 ...

  4. shell脚本执行的三种方式

    (1)  bash script_name 或 sh script_name    推荐使用此方法,script_name 不需要执行权限亦可执行.   (2) path/script_name 或 ...

  5. iOS延时执行的四种方法

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  6. shell脚本去重的几种方法

    测试文件 [root@bogon ~]# cat >test jason jason jason fffffjason 按 Ctr + D保存 1.sort -u [root@bogon ~]# ...

  7. 2.8 补充:shell脚本执行方法

    bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限.   方法一:切换到shell脚本 ...

  8. Shell脚本中引用、调用另一个脚本文件的2种方法

    Shell脚本中引用.调用另一个脚本文件的2种方法 http://www.jb51.net/article/67903.htm

  9. linux安装IPython四种方法

    IPython是Python的交互式Shell,提供了代码自动补完,自动缩进,高亮显示,执行Shell命令等非常有用的特性.特别是它的代码补完功能,例如:在输入zlib.之后按下Tab键,IPytho ...

随机推荐

  1. linux-2.6.38 IIC驱动框架分析

    在linux-2.6内核中,IIC的驱动程序可以大概分为三部分: (1)IIC核心代码:/drivers/i2c/i2c-core.c IIC核心提供了IIC总线驱动和设备驱动的注册.注销方法和IIC ...

  2. PAT Advanced 1073 Scientific Notation (20 分)

    Scientific notation is the way that scientists easily handle very large numbers or very small number ...

  3. mxnet在windows使用gpu 出错

    1. cuda windows安装 官网下载 代码: import mxnet as mxfrom mxnet import ndfrom mxnet.gluon import nn a = nd.a ...

  4. matlab安装MinG-w64 C/C++编译器

    matlab 2018b之编译器的安装 安装MinGW C/C++ 编译器

  5. 《流畅的Python》 Sequence Hacking, Hashing and Slicing(没完成)

    序列修改,散列和切片 基本序列协议:Basic sequence protocol: __len__ and __getitem__ 本章通过代码讨论一个概念: 把protocol当成一个正式接口.协 ...

  6. Qt中使用匿名函数lambda表达式

    一.为什么要使用匿名函数lamdba 首先,lambda表达式可以使代码变得简单,C++中,一个lambda表达式表示一个可调用的代码单元.如代码: #include <QCoreApplica ...

  7. C# EPPlus 导出Excel

    一.Excel导出帮助类 /*引用NuGet包 EPPlus*/ /// <summary> /// Excel导出帮助类 /// </summary> public clas ...

  8. sql prompt工具

    SQL Prompt是一款拥有SQL智能提示功能和格式化Sql代码插件.可用于的SQL Server和VS. SQL Prompt能根据数据库的对象名称,语法和用户编写的代码片段自动进行检索,智能的为 ...

  9. ACM-ICPC 2018 青岛赛区现场赛 K. Airdrop && ZOJ 4068 (暴力)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4068 题意:吃鸡游戏简化为二维平面上有 n 个人 (xi,yi) ...

  10. [Google Guava] 3-缓存

    原文地址  译文地址    译者:许巧辉  校对:沈义扬 范例 01 LoadingCache<Key, Graph> graphs = CacheBuilder.newBuilder() ...