实现同一个文档,不同的帮助文档!

实验目的:源文件,与他的软连接文件,实现其获取到的帮助不一样!

为了让大家更直观的了解该知识点,我在这里先给大家举一个简单的例子!

一、编写一个简单的脚本吧。

[root@localhost app]# vim test.sh 
[root@localhost app]# cat test.sh 
#!/bin/bash
if [ $0 == './test.sh' ];then
	echo hello
else
	echo haha
fi

简单的解释一下:如果我执行test.sh脚本的话,弹出hello,否则弹出haha。

二、给test.sh脚本加上执行权限,并创建一个软连接。

[root@localhost app]# chmod +x test.sh
[root@localhost app]# ln -s test.sh test2.sh
[root@localhost app]# ll
total 4
lrwxrwxrwx. 1 root root  7 Oct 12 08:40 test2.sh -> test.sh
-rwxr-xr-x. 1 root root 80 Oct 12 08:39 test.sh

三、测试

[root@localhost app]# ./test.sh 
hello
[root@localhost app]# ./test2.sh 
haha

看到了吧!test.sh和test2.sh是一个文件,我们执行同样的脚本,出来的结果居然不一样!

你看懂了吗?

----------------------当你的能力不能够满足你的野心,那就静下心来学习吧!----------------------------------------

猜你喜欢

转载自blog.csdn.net/qq_34208467/article/details/83032459