0

for my bash programming assignment i have to create pipelines to process a file to find some patterns. I am currently using the Windows 10 Ubuntu App terminal. I Wrote the following the following :

echo "Processing Log Files..."
# error is the word I'm looking for in the files
grep error -A 1 logfile1.txt >> filter.txt
grep error -A 1 logfile2.txt >> filter.txt
echo "Done."

But when i run the file with the header #!/bin/sh I get this error:

Processing Log Files...
: Directory nonexistentoder.sh: cannot create filter.txt
: Directory nonexistentoder.sh: cannot create filter.txt
Done.

And when i run the code with the header #!/bin/bash i get this error:

Processing Log Files...
: No such file or directoryer.txt
: No such file or directoryer.txt
Done.

I honestly have no idea of why this happens, i changed the permissions of the files to the following:

drwxrwxrwx 0 root root   512 Mar 20 23:25 .
drwxrwxrwx 0 root root   512 Mar 20 13:59 ..
-rwxrwxrwx 1 root root   316 Mar 20 23:24 decoder.sh
-rwxrwxrwx 1 root root 52247 Mar 19 15:59 logfile1.txt
-rwxrwxrwx 1 root root 33142 Mar 19 15:59 logfile2.txt
-rwxrwxrwx 1 root root   239 Mar 19 15:39 mapping-sorted.txt
  • Are you running the script as root or as a user ? – Panther Mar 21 '18 at 5:54
  • 1
    Whenever you see text smooshed together like directoryer.txt the most likely issue is that the script has been created/saved with Windows line endings (CR/LF rather than plain LF) – steeldriver Mar 21 '18 at 5:57
  • @steeldriver That might be the issue since in edition the files using a windows program, rather than a terminal editor – Diego Rodriguez Mar 21 '18 at 6:11
2

Thanks to @steeldriver I found out that the script i wrote had hidden windows characters, since i was using a windows text editor. I ran the following line, and the file had the header #!/bin/bash.

dos2unix scriptName.sh

the script worked afterwards :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.