I am working on a shell script that takes a single command line parameter, a file path (might be relative or absolute). The script should examine that file and print a single line consisting of the phrase:
if the files is an ASCII text file with CR/LF line terminators, or
if the file is binary or ASCII with “Unix” LF line terminators.
currently I have tried the following code.
#!/bin/sh file=$1 if grep -q "\r\n" $file;then echo Windows ASCII else echo Something else fi #!/bin/sh if test -f "$file" then echo Windows ASCII else echo Something else fi #!/bin/sh file=$1 case $(file $file) in *"ASCII test, with CRLF lin terminators") echo "Windows ASCII" ;; *) echo "Something else" ;; esac
All cases displays information properly, but when I pass something that is not of Windows ASCII type through such as /bin/cat or SomeFile.sh it still id's it as Windows ASCII. When I pass a .doc file type it displays something else as expected it is just on folders that it displays Windows ASCII. I think I am not handling it properly, but I am unsure. Any pointers of how to fix this issue?