执行脚本提示shell-init: error retrieving current directory:getcwd问题分析

近日,在部署完我们的程序后,调用脚本启动程序突然提示错误:

shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

[root@smart hello]# cat /root/Desktop/hello.sh 
#!/bin/bash
echo "hello"
[root@smart hello]# /root/Desktop/hello.sh
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
hello

对此问题,想来也十分奇怪,之前虽有出现也未进行深究,今天闲来无事就研究了下这个问题。

这个问题细细看来就是“No such file or directory”当前所处目录被删除。如下:

[root@smart hello]# cat /root/Desktop/hello.sh 
#!/bin/bash
echo "hello"
[root@smart hello]# /root/Desktop/hello.sh
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
hello
[root@smart hello]# cd /
[root@smart /]# /root/Desktop/hello.sh
hello
[root@smart /]# 

同样将脚本中的解析器申明去掉,也可以得到这个效果。推测是调用解析器时需要提取当前目录导致上述错误提示。

[root@smart hello]# cat /root/Desktop/hello.sh 
echo "hello"
[root@smart hello]# /root/Desktop/hello.sh
hello

Juyin@2018/2/1

你可能感兴趣的:(经验分享)