The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Getting error in command line arguments sunitachoudhury Shell Programming and Scripting 9 01-14-2009 09:13 PM
Compliation Error in solaris - macro "min" requires 2 arguments, but only 1 given learningkid SUN Solaris 0 01-29-2008 05:23 AM
FD0 error code 30 Pritpal singh UNIX for Advanced & Expert Users 6 08-28-2006 06:55 AM
arguments too long error kburrows Shell Programming and Scripting 0 07-21-2006 12:35 PM
arguments expected error strike Shell Programming and Scripting 4 05-18-2005 08:18 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-18-2008
Brewer27 Brewer27 is offline
Registered User
  
 

Join Date: May 2008
Posts: 5
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 (permalink)  
Old 05-18-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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 (permalink)  
Old 05-18-2008
Brewer27 Brewer27 is offline
Registered User
  
 

Join Date: May 2008
Posts: 5
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0