0

I'm working on a Milestone for my IT class and I've written a Linux script using the vi editor that should perform the necessary tasks. The instructions direct me to create a script within the vi editor that creates a text file into which the current date is written, creates a directory entitled COPY, copies the previously created text file into the new directory, and renames the directory with the title of the file.

The script I have is the following

#!/bin/bash
date > Time_File.txt
mkdir -p COPY
cp Time_File.txt COPY
mv COPY Time_File

For some reason, after changing to the appropriate permissions within the Codio terminal I'm using, running this script will produce the Time_File.txt just fine and with the appropriate content, but the COPY directory appears like a file might on the left hand side and whenever I click to see the contents, an error message is given. The error message says "IOException: Error during file operation. Internal Error" and I'm not entirely sure what that means.

I've tried several solutions including reordering the code but nothing I do seems to work. Any suggestions?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Sarah
  • 55
  • 1
  • 5
  • 1
    Why do you create a directory named `COPY`, only to change its name after the copy is complete? `mkdir -p Time_File; cp Time_File.txt Time_file` should be equivalent. – chepner Feb 09 '20 at 18:18
  • That said, `bash` doesn't raise exceptions; that error message is coming directly from the terminal, and shouldn't be related to the script itself. – chepner Feb 09 '20 at 18:19
  • Although, it's possible your script has DOS line endings, in which case you created a directory named `COPY\r`, not `COPY`, which would cause `mv` to be trying to rename the wrong directory. – chepner Feb 09 '20 at 18:20
  • I need to create the directory COPY and then change it because that is part of the assignment; demonstrating my ability to do that. I will try running the scrip itself once more after maybe reloading the terminal. Thanks for your comments! – Sarah Feb 09 '20 at 19:27
  • 1
    In `vi`, do `:set list`. It will show you invisible characters that might be present. – Nic3500 Feb 10 '20 at 01:25

0 Answers0