开发者

Bash script to mkdir

I am trying to create a directory based on a variable entered by a user and then save files there.

I thought this would be simple enough for me but I get an error message "No such file or directory" when I try to save there. When I hit "ls" it li开发者_运维技巧sts the directory with a "?" after it.

I am working with an .sh script on a Mac terminal.

Relevant code:

#get user input
echo "enter the collection number"
read COLLECTION
#create the directory
mkdir "$COLLECTION"dir
#calculate a checksum and save it to the above directory
sudo openssl md5 /dev/disk1 > "$COLLECTION"dir/md5.txt

--


Check you script to see if you have DOS style line endings (\r\n). You can safely run dos2unix on the script if you aren't sure.

The ? you see in the file name may actually be the carriage return at the end of the line (since Bash doesn't treat that as whitespace).

So "$COLLECTION"dir/ doesn't exist; "$COLLECTION"dir\r/ does.

Edit: Vi usually does a good job showing you what those special characters are.

ls | vi -


The only piece of this code likely to give you a "No such file or directory" error is the last line. Does /dev/disk1 exist on your machine?


I use mkdir -p when I get that error ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜