[英]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.