环境变量

环境变量

可执行文件放到环境变量里面才有意义

1.
[root@web01 ~]# vim a.txt	#编辑文件,写入命令
ls -l
[root@web01 ~]# ll
total 16
-rw-------. 1 root root 1444 May  8 04:01 anaconda-ks.cfg  
-rw-r--r--  1 root root   10 May 11 21:46 a.txt  # 没有执行权限,但是root可以执行
[root@web01 ~]# sh a.txt 	#a.txt实际上就是一个脚本
total 16
-rw-------. 1 root root 1444 May  8 04:01 anaconda-ks.cfg
-rw-r--r--  1 root root   10 May 11 21:46 a.txt

2.
[root@web01 ~]# vim web02
ssh root@172.16.1.8 >/dev/null
[root@web01 ~]# sh web02	
#该文件没有添加执行权限,所以只能 sh web02来执行(在别的目录下需要用绝对路径来执行)
Last login: Mon May 11 21:52:29 2020 from 172.16.1.7
[root@web02 ~]# 	
#登录成功,第一次执行要输入yes和密码,第二次直接输入密码

3.
#自己做了一个命令,达到指定的目的
[root@web01 ~]# vim web02
ssh root@172.16.1.8 >/dev/null
[root@web01 ~]# chmod u+x web02 
[root@web01 ~]# ll
total 20
-rw-------. 1 root root 1444 May  8 04:01 anaconda-ks.cfg
-rwxr--r--  1 root root   20 May 11 21:51 web02		#添加了执行权限,可以直接执行
[root@web01 ~]# mv web02 /usr/bin/	#移到环境变量 目录下,或者将改文件所在目录加入到环境变量,可以直接执行 和TAB
[root@web01 ~]# we
weak-modules  web02         
[root@web01 ~]# web02 
Last login: Mon May 11 21:54:10 2020 from 172.16.1.7
[root@web02 ~]#			#执行成功
原文地址:https://www.cnblogs.com/syy1757528181/p/12873408.html