-
The problem statement, all variables and given/known data:
Write 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:
Windows ASCII
if the files is an ASCII text file with CR/LF line terminators, or
Something else
if the file is binary or ASCII with �Unix� LF line terminators. -
Relevant commands, code, scripts, algorithms:
Output should look like this:
./fileType.sh ~cs252/Assignments/ftpAsst/d3.dat
Windows ASCII
./fileType.sh /bin/cat
Something else
./fileType.sh fileType.sh
Something else
./fileType.sh /usr/share/dict/words
Something else
- The attempts at a solution (include all code and scripts):
The first attempt I tried worked on files, but when I ran it on folders it outputted Windows ASCII. The second attempt I tried works, but only outputs Windows ASCII.
#!/bin/sh
file=$1
if grep -q "\r\n" $file;then
echo Windows ASCII
else
echo Something else
fi
and I have tried this:
#!/bin/sh
if test -f $file;
then
echo "Windows ASCII"
else
echo "Something else"
fi
Third attempt.
#!/bin/sh
file=$1
case $(file $file) in
*"ASCII test, with CRLF lin terminators")
echo "Windows ASCII"
;;
*)
echo "Something else"
;;
esac
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Old Dominion University, Norfolk VA USA, Professor Steven Zeil, CS 252
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).