ホームページ > 運用・保守 > Linuxの運用と保守 > Linux がファイルを見つけられない場合の対処方法

Linux がファイルを見つけられない場合の対処方法

藏色散人
リリース: 2019-11-14 09:12:30
オリジナル
7139 人が閲覧しました

Linux がファイルを見つけられない場合の対処方法

Linux がファイルを見つけられない場合はどうすればよいですか?

Linux ソース シェル スクリプトで、ファイルが見つからないことが示されています。

例:

[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 [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 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
Linuxの基礎を学ぶ
から 1970-01-01 08:00:00
0
0
0
Linux でサーバー ログを表示する方法
から 1970-01-01 08:00:00
0
0
0
Linux でデータベースに接続する
から 1970-01-01 08:00:00
0
0
0
Linux でファイル名をバッチで変更する
から 1970-01-01 08:00:00
0
0
0
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート