Having trouble with this problem, i could use some help ....
create a shell script, fileType.sh, 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.
For example:
% ./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
%
Your script should not produce any other output when given a legal path to an existing file. (It may produce anything you like if given an incorrect path to a non-existent file.)
If the output of the file command contains the phrase “ASCII text” and the phrase “CRLF”, then the file is Windows ASCII text.
New to Unix; I have some C++ experience.
This is what I have in my script.
#!/bin/sh
line='file -b "$1"`
win=o
for i in $line; do
if test `expr match "$1" "CRFL" | expr match "$1" "ASCII"` -gt 0 ; then
win =1
break
fi
done
if test "$win" -eq 1; then
printf "Windows ASCII\n"
else
printf "Something else\n"
fi
I am using tcsh and basically I am trying to search for two varribles at the same time. In C++ I would use the "&&" operator. I don't know if unix has such an operator so I have tried to "pipe" them together.... with no luck.
I am getting "Something else" when I should be getting "Windows ASCII"
tcshscript, so your tagging is inaccurate since the problem is not the shell you run your commands from but the shell that runs this script. The use of the|in theifis dubious;testdoesn't generate output on standard output andexprdoesn't read anything from standard input. You may be thinking of the||operator. Using$1instead of$iin the tests is also probably a mistake. Consider using thecaseoperator too.|is part of the command substitution that provides the arguments fortest(which would be easier to see if the OP weren't using backquotes rather than$(...)).