if-then


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if-then
# 1  
Old 11-04-2011
if-then

Hello,

I have this sentence that doesn't work:

Code:
if ['echo "$by_ln" | cut -d " " -f1,2 | wc -l' != 'echo "$by_ln" | cut -d " " -f1,2 | uniq | wc -l'];



But if I separate the statement on two and run works well. Why? Whats wrong?

Code:
echo "$by_ln" | cut -d " " -f1,2 | wc -l 
echo "$by_ln" | cut -d " " -f1,2 | uniq | wc -l 

Cheers!!!

Last edited by Franklin52; 11-05-2011 at 10:00 AM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 11-04-2011
You forgot tons of spaces. They're not optional.

Code:
if [ condition ]
then
...
fi

Also, you used single quotes, '' not backticks, `` Things in single quotes don't execute.

Also, if this "$by_ln" contains multiple lines, as seems likely, that's a very dangerous way to program because you're likely to hit the maximum size of a shell variable -- which is very small on many systems.

Also, you don't need to run cut so many times to get one field.

If you show me what your program's trying to do, I'll find a better way.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question