首頁  >  文章  >  運維  >  linux找不到文件怎麼辦

linux找不到文件怎麼辦

藏色散人
藏色散人原創
2019-11-14 09:12:307035瀏覽

linux找不到文件怎麼辦

linux找不到檔案怎麼辦?

linux source shell腳本顯示找不到檔案

範例: 

[root@localhost osc]# sh a.sh 
a.sh: line 4: source: 1.sh: file not found
[root@localhost osc]# cat a.sh 
#!/bin/bash
cd /data/osc/bin/
if [ -f 1.sh ];then
source 1.sh
fi

剛開始,還以為權限問題,然後給權限,但結果還是一樣

man source ,找到原因了。 source時找filename的問題。

source 指令找filename是在目前的shell環境下找的,如果沒有反斜線,就在path找,如果沒有就沒有。

source filename [arguments]
              Read  and  execute commands from filename in the current shell environment and return the exit status of the last command exe-
              cuted from filename.  If filename does not contain a slash, file names in PATH are used to find the directory containing file-
              name.   The  file  searched  for  in  PATH  need  not be executable.  When bash is not in posix mode, the current directory is
              searched if no file is found in PATH.  If the sourcepath option to the shopt builtin command is turned off, the  PATH  is  not
              searched.   If  any  arguments  are  supplied, they become the positional parameters when filename is executed.  Otherwise the
              positional parameters are unchanged.  The return status is the status of the last command exited within the script  (0  if  no
              commands are executed), and false if filename is not found or cannot be read.

如下方式都可以:

1、將腳本所在的目錄加到PATH中

2、加上相對路徑或絕對路徑

3.就算是當前目錄也得加./

推薦:《Linux教程

以上是linux找不到文件怎麼辦的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn