![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|