简体   繁体   中英

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:

#!/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

I am even using sudo so there's definitely no permission problem.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM