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.
3 More Discussions You Might Find Interesting
1. Programming
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
2. Shell Programming and Scripting
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. Shell Programming and Scripting
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