How to fix :[too many arguments error in code


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to fix :[too many arguments error in code
# 1  
Old 05-18-2008
How to fix :[too many arguments error in code

I am getting a :[ too many arguments error on line 28 if I do not specify a directory or file when running my code. Any suggestions as I am stuck here.

if [ $# -gt 1 ]; then
echo "Enter zero or one file"
echo "You must use a valid directory"
echo "Current directory is:" pwd
exit 0
fi
#Flag Variable
flag=1
#Code for no arguments
if [ $# -eq 0 ]; then
for filename in *
do
if [ -f $filename ]; then
linetest1='wc -l < $filename'
# Execution
if [ $flag -eq 1 ]; then
startline=$linetest1
startfile=$filename
flag=2
fi

#End Code Execution
if [ $startline -lt $linetest1 ]; then
startline=$linetest1
startfile=$filename
fi
fi
done
echo "File $startfile has the maximum number lines ($startline)."
exit 0
fi

#If only one Variable
if [ $# -eq 1 ]; then
cd $1
for filename in *
do
if [ -f $filename ]; then
linetest1='wc -l < $filename'
if [ $flag -eq 1 ]; then
startline=$linetest1
startfile=$filename
flag=2
fi
if [ $startline -lt $linetest1 ]; then
startline=$linetest1
startfile=$filename
fi
fi
done
echo "File $startfile has the maximum number lines ($startline)."
exit 0
fi



Thanks.
# 2  
Old 05-18-2008
Typically this error is because you don't quote your variables properly, and invoke [ with an empty variable.

As a rule of thumb, use double quotes around all your variables.
# 3  
Old 05-18-2008
So I am looking at my code and I see that where I am setting linetest1 = to something I have a ' around it. Is that my problem or should I be looking elsewhere. Sorry, I am new to UNIX and coding in general.

Thanks again.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help me please to fix my error

Can you help me to fix my error please?! I checked the code and I think there is no mistake, but when I run it gives me error such line 1: /Users/Manu/trials/hosts: is a directory sort: open failed: /Users/Manu/trials/hosts/*: No such file or directory Help me please... mycode NAME value.... (9 Replies)
Discussion started by: Manu1234567
9 Replies

2. Shell Programming and Scripting

How to fix my code in Perl?

Hi Perl users, Could you help me how to fix my code so I can get the expected output as seen below? is there missing in my program? Thank You #!/usr/bin/perl -w use strict; open (FH, "< file1.log") or die $!; open (FL, "< file2.log") or die $!; my $file = "result.log"; my... (1 Reply)
Discussion started by: askari
1 Replies

3. Programming

why ORA-00600: internal error code, arguments: [17059]?

I have code to update some records in MyTable1 in sql which I am calling from ksh file (unix script). I am getting below error - MyTable1 TABLE UPDATE FAILED : UPDATE MyTable1 SET ph_nr = '+44 (0)20 8960 1233' , update_dts = sysdate WHERE ID = 499037 ORA-00600: internal error code,... (2 Replies)
Discussion started by: rshivarkar
2 Replies
Login or Register to Ask a Question