Reputation: 1
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 lists the directory with a "?" after it.
I am working with an .sh script on a Mac terminal.
#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
--
Upvotes: 0
Views: 3789
Reputation: 24072
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 -
Upvotes: 3
Reputation: 1006
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?
Upvotes: 1