Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I try to make a Script, which verify the lines in a File.
Dos File has 3 lines = dothis1
Dos File NOT have 3 lines = dothat2unfortunately the if-then-else-command get always FALSE (dothat2). Even if the File has only 3 Lines. What is wrong in this command?
Script:
#################################
#!/bin/bash
if [[ 'wc -l < test.log' == "3" ]]
then
echo "File has 3 Lines!"
else
echo "File dos NOT have 3 Lines!"
fiecho "number of lines in File:"
wc -l < test_mail.log

for equlaity in bash it is -eq
So rewrite
if [[ 'wc -l < test.log' == "3" ]]
as
if [ `wc -l < test.log` -eq 3 ]Moreover in the last you are printing the number of lines in test_mail.log instead of test.log
HTH
Jc

Thank you for your help.
but now I receive these messages:
__________________________________
. testLog.sh
[: wc -l < test.log: integer expression expected
File dos NOT have 3 Lines!
Number of lines in File:
3
__________________________________
I have adjust the last command to proove the 3 Lines. "test.log" exists and has 3 Lines.

The corrected solution posted by jeyachitra will work. A nested command must be enclosed in back-quotes, as shown in the corrected solution. When it is enclosed in single-quotes, it becomes just a string constant, and of course the -eq wants an integer. And since you are comparing integers, notice that the corrected solution does not enclose the 3 in double-quotes, although this would be OK since they will be removed by the shell.
A more updated way to code an embedded command (for ksh and bash) is:
if [ $(wc -l < test.log) -eq 3 ]

GREAT... it works!
I think, I probably used the wrong quotes.. (fool)...
I took your command:
if [ $(wc -l < test.log) -eq 3 ]
And it worked properly.Thank you very much Jim and Jeyachitra,
Greetings from Switzerland, jerome

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |