bash 如何解决 UNIX 中的 Not a Directory 错误消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15309244/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:47:19  来源:igfitidea点击:

how to solve a Not a Directory error message in UNIX

linuxbashshellunixsh

提问by gmhk

I have created a directory with the following command

我使用以下命令创建了一个目录

/usr/bin/mkdir -p  "${exa}/isrvce-backup";

exa ---> /sample/example

exa ---> /样本/示例

and I see isrvce-backup is created, when I tried to access that folder, I get the following error message

我看到 isrvce-backup 已创建,当我尝试访问该文件夹时,收到以下错误消息

isrvce-backup is not a Directory

Can any one help how to resolve this issue and I am using Shell script

任何人都可以帮助如何解决此问题,我正在使用 Shell 脚本

When I execute lscommand I can see isrvce-backupentry in that list

当我执行ls命令时,我可以看到isrvce-backup该列表中的条目

I tried to access that folder, as cd isrvce-backupcommand

我试图访问该文件夹,作为cd isrvce-backup命令

Edit :After Executing the ls -l isrvc*command I get the following output

编辑:执行ls -l isrvc*命令后,我得到以下输出

-rwx------+ username none 37 date/time  isrvce-backup

if I see the desc of the isrvce-backup folder, it seems to be file.

如果我看到 isrvce-backup 文件夹的描述,它似乎是文件。

I am wondering how mkdir will create a folder with file persmissions, instead as a complete Directory

我想知道 mkdir 如何创建一个具有文件权限的文件夹,而不是一个完整的目录

2) I tried creating the same directory directly in the unix box, it worked fine but some how its not wokring from the shell script.

2)我尝试直接在 unix 框中创建相同的目录,它工作正常,但有些如何它不是从 shell 脚本工作的。

回答by balusss

I coudln't reproduce the error you mentioned. I use bash-3.2 and see the directory being created as intended.. If you are trying this with bash, then please specify your bash version (or any other shell), exact code snippet causing this error and the output of following commands on the directory being created (cat,ls -l,file,stat) etc..

我无法重现您提到的错误。我使用 bash-3.2 并看到按预期创建的目录。正在创建的目录(cat、ls -l、file、stat)等。

$ cat mkdir.sh
#! /bin/bash
exa="/sample"
mkdir -p "${exa}/c"
touch "${exa}/c/d"
file "${exa}/c/d"

$ sudo bash mkdir.sh  ## asks password as the dir is being created on /
Password: 
/sample/c/d: empty

$ ls -l /sample/
total 0
drwxr-xr-x  3 root  wheel  102 Mar  9 18:02 c

$ ls -l /sample/c
total 0
-rw-r--r--  1 root  wheel  0 Mar  9 18:07 d