views:

67

answers:

3

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.

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

--

+1  A: 

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?

Larry Wang
A: 

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

ramesh
+2  A: 

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 -
dave
Thanks!This fixed the problem. I guess I had a carriage return left over from something or other.
You can use `ls -lb` to show you the control characters in a filename.
Dennis Williamson