linux中执行可执行文件的命令(./,.,source,sh,bash)

您所在的位置:网站首页 linux绝对路径命令 linux中执行可执行文件的命令(./,.,source,sh,bash)

linux中执行可执行文件的命令(./,.,source,sh,bash)

2024-07-14 11:30:51| 来源: 网络整理| 查看: 265

博客园连接: 在linux里,source、sh、bash、./都可以执行shell script文件,那它们有什么不同吗? 博客园连接

个人认为source、sh、bash,. 这几个都是将文件当sh文件来执行的,如果是py文件乃至其他文件那,那么他将不能识别(linux中需要在第一行申明文件执行的程序) 直接将文件绝对路径放到命令行或者./xxxxx放到命令行,也会执行,执行是按照你申明的程序来执行的

source 在当前shell内去读取 sh 都是打开一个subshell去读取(子shell) bash 都是打开一个subshell去读取(子shell) ./ 打开一个subshell去读取

sh文件的执行 [root@iZbp11vz1brexya9wf6w6eZ home]# ll total 8 drwx------ 2 weihang weihang 4096 Jul 16 21:17 weihang drwxr-xr-x 2 root root 4096 Jul 5 22:23 weihang2 [root@iZbp11vz1brexya9wf6w6eZ home]# cat /home/weihang/test.sh #!/usr/bin/bash echo "11111111111111111111111111111111111" [root@iZbp11vz1brexya9wf6w6eZ home]# ./weihang/test.sh 11111111111111111111111111111111111 [root@iZbp11vz1brexya9wf6w6eZ home]# ./weihang/test.sh 11111111111111111111111111111111111 [root@iZbp11vz1brexya9wf6w6eZ home]# /weihang/test.sh -bash: /weihang/test.sh: No such file or directory [root@iZbp11vz1brexya9wf6w6eZ home]# ./weihang/test.sh 11111111111111111111111111111111111 [root@iZbp11vz1brexya9wf6w6eZ home]# source /weihang/test.sh -bash: /weihang/test.sh: No such file or directory [root@iZbp11vz1brexya9wf6w6eZ home]# source /home/weihang/test.sh 11111111111111111111111111111111111 [root@iZbp11vz1brexya9wf6w6eZ home]# . /home/weihang/test.sh 11111111111111111111111111111111111 [root@iZbp11vz1brexya9wf6w6eZ home]# vim /home/weihang/test.sh [root@iZbp11vz1brexya9wf6w6eZ home]# cat /home/weihang/test.sh echo "11111111111111111111111111111111111" [root@iZbp11vz1brexya9wf6w6eZ home]# [root@iZbp11vz1brexya9wf6w6eZ home]# . /home/weihang/test.sh 11111111111111111111111111111111111 [root@iZbp11vz1brexya9wf6w6eZ home]# source /home/weihang/test.sh 11111111111111111111111111111111111 [root@iZbp11vz1brexya9wf6w6eZ home]# ./home/weihang/test.sh -bash: ./home/weihang/test.sh: No such file or directory [root@iZbp11vz1brexya9wf6w6eZ home]# sh /home/weihang/test.sh 11111111111111111111111111111111111 [root@iZbp11vz1brexya9wf6w6eZ home]# bash /home/weihang/test.sh 11111111111111111111111111111111111 [root@iZbp11vz1brexya9wf6w6eZ home]# `/home/weihang/test.sh` -bash: 11111111111111111111111111111111111: command not found [root@iZbp11vz1brexya9wf6w6eZ home]# py文件的执行 [root@iZbp11vz1brexya9wf6w6eZ home]# cat weihang/pytest.py #!/usr/bin/python print "sssssssssssssssssss" a = [1,2,3,4,5] print a [root@iZbp11vz1brexya9wf6w6eZ home]# -rwxrwxrwx 1 root root 70 Jul 16 21:44 pytest.py -rwxrwxrwx 1 root root 44 Jul 16 21:33 test.sh [root@iZbp11vz1brexya9wf6w6eZ weihang]# sh pytest.py pytest.py: line 2: print: command not found pytest.py: line 3: a: command not found pytest.py: line 4: print: command not found [root@iZbp11vz1brexya9wf6w6eZ weihang]# bash pytest.py pytest.py: line 2: print: command not found pytest.py: line 3: a: command not found pytest.py: line 4: print: command not found [root@iZbp11vz1brexya9wf6w6eZ weihang]# ./pytest.py sssssssssssssssssss [1, 2, 3, 4, 5] [root@iZbp11vz1brexya9wf6w6eZ weihang]# . pytest.py -bash: print: command not found -bash: a: command not found -bash: print: command not found [root@iZbp11vz1brexya9wf6w6eZ weihang]# . pytest.py -bash: print: command not found -bash: a: command not found -bash: print: command not found [root@iZbp11vz1brexya9wf6w6eZ weihang]# source pytest.py -bash: print: command not found -bash: a: command not found -bash: print: command not found [root@iZbp11vz1brexya9wf6w6eZ weihang]# python pytest.py sssssssssssssssssss [1, 2, 3, 4, 5] [root@iZbp11vz1brexya9wf6w6eZ weihang]# cd .. [root@iZbp11vz1brexya9wf6w6eZ home]# ll total 8 drwx------ 2 weihang weihang 4096 Jul 16 21:44 weihang drwxr-xr-x 2 root root 4096 Jul 5 22:23 weihang2 [root@iZbp11vz1brexya9wf6w6eZ home]# pwd /home [root@iZbp11vz1brexya9wf6w6eZ home]# /home/weihang/pytest.py sssssssssssssssssss [1, 2, 3, 4, 5] [root@iZbp11vz1brexya9wf6w6eZ home]# ./home/weihang/pytest.py -bash: ./home/weihang/pytest.py: No such file or directory [root@iZbp11vz1brexya9wf6w6eZ home]# pwd /home [root@iZbp11vz1brexya9wf6w6eZ home]# /weihang/pytest.py -bash: /weihang/pytest.py: No such file or directory [root@iZbp11vz1brexya9wf6w6eZ home]# ./weihang/pytest.py sssssssssssssssssss [1, 2, 3, 4, 5] [root@iZbp11vz1brexya9wf6w6eZ home]# [root@iZbp11vz1brexya9wf6w6eZ weihang]# a=`/home/weihang/pytest.py` [root@iZbp11vz1brexya9wf6w6eZ weihang]# echo ${a} sssssssssssssssssss [1, 2, 3, 4, 5] [root@iZbp11vz1brexya9wf6w6eZ weihang]#


【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭