简体   繁体   English

cp : 没有这样的文件或目录 bash 脚本

[英]cp : no such file or directory bash script

Why is It that I am not able to create a file?为什么我无法创建文件? Here is my bash script:这是我的 bash 脚本:

#!/bin/bash

var=$(date +"%D")

sudo cp ./script1.sh "$var _script1.txt"

It's showing this error:它显示此错误:

cp: cannot create regular file '01/23/20 _script1.txt': No such file or directory cp: 无法创建常规文件 '01/23/20 _script1.txt': 没有那个文件或目录

I am even using sudo so there's definitely no permission problem.我什至在使用 sudo 所以绝对没有权限问题。

Your date variable contains / but you should not have / inside a filename.您的日期变量包含/但你不应该有/文件名内。 See this看到这个

I would suggest you change your variable to the below format (using - instead as separators) :我建议您将变量更改为以下格式(使用-代替分隔符):

var=$(date +%M-%d-%Y)

With this format your copy operation should work使用这种格式,您的复制操作应该可以工作

You can't it's prohibited.你不能它被禁止。 But you can always use work around.但是您始终可以使用变通方法。 For example use one of these sign.例如,使用这些标志之一。 ( ⟋ ⁄ ∕ ⧸ ⁄ ) ( ⟋ ⁄ ∕ ⧸ ⁄ )

 mkdir "⧸test"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的bash脚本中不断显示“ cp:无法统计”:没有这样的文件或目录或“ cp:缺少操作符” - Why do I keep getting “cp: cannot stat '': No such file or directory” or “cp: missing opereand” in my bash script cp命令不在sh \\ bash脚本中创建目录,为什么? - cp command don't create directory in a sh\bash script, why? Bash 脚本 - 使用 find -exec cp 的 For 循环产生错误:cp:省略目录 - Bash Script - For loop using find -exec cp produces error: cp: omitting directory unix中的shell脚本(在bash shell中),用于将文件从一个位置(即目录)复制到另一位置,而完全不使用cp命令 - shell script in unix(in bash shell) for copying a file from one location(i.e a directory), to other, without using cp command at all 防止'cp'从bash脚本输出文件名 - Prevent 'cp' from outputting the file name from a bash script cp:无法统计…没有此类文件或目录 - cp: cannot stat … No such file or directory cp: cannot stat No such file or directory - cp: cannot stat No such file or directory CGI脚本未执行bash命令(如“ CP”) - CGI script not executing bash commands such as 'CP' bash 脚本:如何应对不同的 cp 行为? - bash script: how to cope with the different cp behaviors? 在新文件目录下运行bash脚本? - Run a bash script when new file directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM