|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Usage of wc within a shell script
Hi,
I have a shell script that produces a file that has a bunch of names. Then I have to ftp it to a remote site. Occasionally, I could have an empty file. In that case, I should not ftp the file. So, I would like to count the lines in a file that is produced. How can I accomplish the counting of the lines part? I tried something like this. It is not working: lcount = wc -l '$filename' if !($lcount eq 0) ftp Any help would be greatly appreciated. Also I noticed that wc -l <filename> at the command prompt produces not only the linecount but also the filename. Thanks, Sankar. |
|
#2
|
|||
|
|||
|
RE: Usage of wc within a shell script
|
|
#3
|
|||
|
|||
|
RE: Usage of wc within a shell script
I agree, use the -s switch. It might not work because you're missing backtics in your lcount variable. Remember, command strings *should* be enclosed in backtics (`) your variable, originally written as:
lcount = wc -l '$filename' would therefore be: `lcount = wc -l $filename` I also noticed that in your string, you were using forward tics ('). Remember, when shell scripting, forward tics tell the script to take the text litterally. Instead of running the command wc, it was defining the variable to read the text "wc -l $filename". If I were to build a script like that, this is what it would look like: Code:
lcount= `wc -s $filename`
if [$lcount eq 0]
then
{
exit;
}
else
{
ftp chickenbox.com #or whatever your target
user pass
put $filename
bye
}
fi
Hope this helps, Eric |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Server Administration > Usage of wc within a shell script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|