I have a very simple shell script name test.sh:
[mylinux ~]$ cat test.sh
echo "a"
echo "${0}"
However, when I sourceand it sh, the results are completely different:
[mylinux ~]$ sh test.sh
a
test.sh
[mylinux ~]$ source test.sh
array : x, y
0,x
1,x
I can not understand the results source test.sh, and after I changed the name test.sh, the results also changed:
[mylinux ~]$ mv test.sh a.sh
[mylinux ~]$ source a.sh
a
-bash
How can I understand this phenomenon?
BTW, the second strange result comes out only on one of my remote linux sessions, everything works fine on my local Linux system. So it’s probably related to the environment and what can I do to find the root cause?
I found the real problem, that is, even if they don’t have such a file test.sh, I can even execute source test.shto get the results:
[mylinux ~]$ rm test.sh
[mylinux ~]$ source test.sh
array : x, y
0,x
1,x
This is pretty weird for me ...