0

I am creating a log file to record user activity and also allow them to add a comment. I would like the name of the log file to be the original file and the current time here's my code

currentDate=$(date)
logFileName="$file_name $currentDate.log"
            
echo "$USER signed in called $file_name on " $(date) >>logFolder/$repo_name/$logFileName
read comment
echo $comment>>logFolder/$repo_name/$logFileName

but I keep getting ambiguous redirect.

edit: my script allows users to create a directory, add a new file to the directory and change the directory. When they perform any action a corresponding directory it's created in the logFolder which houses any activity done in the respective directory I also want to give the user the opportunity to add additional comments further explaining what they did. Their comment is then appended to a log file with the name of the log file being "the file they were currently working on and the current date"

e.g pizza.html Sat Oct 30 19:13:11 BST 2021

here's a picture of my terminalenter image description here

Casper Josh
  • 31
  • 1
  • 6
  • please provide your expected output with concrete data and the given output/problem as exact as possible – D-E-N Oct 30 '21 at 17:48
  • Since `logFileName` contains a space, I would highly recommend wrapping it with `"` when you use it. It is generally a good practice to wrap all variables with double quotes when using them, to avoid surprises caused by spaces. – Zois Tasoulas Oct 30 '21 at 17:55
  • E.g., `echo "$USER signed in called $file_name on " $(date) >> "logFolder/$repo_name/$logFileName"`, notice the double quotes around `logFolder` and `logFileName` – Zois Tasoulas Oct 30 '21 at 17:56
  • As @D-E-N mentioned, providing more details on the problem you observe will be helpful to give more precise help. – Zois Tasoulas Oct 30 '21 at 17:58
  • @zois It works, it creates a file in the logFolder under the current directory I'm working on but the filename is just the date the name of the file is not included here's an example Sat Oct 30 19:49:35 BST 2021.log – Casper Josh Oct 30 '21 at 18:54
  • @D-E-N i have edited the question, i added some more information and a picture of the output I'm getting – Casper Josh Oct 30 '21 at 18:55
  • Please [don’t post images of code or error messages.](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557) – tripleee Oct 30 '21 at 20:42

0 Answers0