Linux如何运行文件?操作方法详解!

更新时间:02-04 教程 由 枝桠 分享

  在Linux系统中,运行文件的方式{BANNED}最佳常见的主要分为4种:1、使用source执行文件;2、利用“.”执行文件;3、使用bash执行脚本文件;4、使用“./file”执行脚本文件,接下来通过这篇文章为大家详细介绍一下。

  一、创建文件

  vi test.txt

  # 按i切换insert模式

  # 输入文本

  #!/bin/bash

  echo "hello world!!!"

  echo $$ # 打印当前进程id

  echo $test

  二、运行文件常见的方式

  1、使用source执行脚本

  test=100

  source test.txt

  输出:

  Hello world!!!

  37790

  100

  使用的为当前bash

  2、使用.执行脚本

  . test.txt

  Hello world!!!

  37790

  100

  使用的为当前bash

  3、使用bash执行脚本

  bash test.txt

  Hellow world!!!

  47733

  进程id更新了,且未获取到变量test的值,因为启动了子进程的bash执行脚本。

  4、使用./file执行脚本

  注意:此种方式首先得给脚本添加执行权限chmod +x test.txt

  ./test.txt

  Hello world!!!

  47758

  进程id更新了,且未获取到变量test的值,因为启动了子进程的bash执行脚本。

声明:关于《Linux如何运行文件?操作方法详解!》以上内容仅供参考,若您的权利被侵害,请联系13825271@qq.com
本文网址:http://www.25820.com/tutorial/14_915250.html