Name: jerome Date: August 26, 2004 at 01:40:31 Pacific Subject: Unix, Script, If then else OS: SUN CPU/Ram: -
Comment:
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 = dothat2
unfortunately 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!" fi
echo "number of lines in File:" wc -l < test_mail.log
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: