Test - too many arguments | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Test - too many arguments

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-28-2011
locoroco locoroco is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 15 February 2014, 7:50 PM EST
Posts: 127
Thanks: 44
Thanked 3 Times in 3 Posts
Test - too many arguments

How do I prevent the message "too many arguments" to appear when using this script?


Code:
name="one two three four five six seven"
if test $name=""
then
echo "Empty variable"
else
echo "Value assigned"
fi

output:
bash: test: too many arguments
Value assigned
Sponsored Links
    #2  
Old 03-28-2011
michaelrozar17's Avatar
michaelrozar17 michaelrozar17 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 17 March 2014, 1:43 AM EDT
Location: IN
Posts: 892
Thanks: 14
Thanked 182 Times in 173 Posts
Quote the variable and try..

Code:
if test "$name"=""

The Following 2 Users Say Thank You to michaelrozar17 For This Useful Post:
dania moreno (07-17-2012), locoroco (03-28-2011)
Sponsored Links
    #3  
Old 03-28-2011
locoroco locoroco is offline
Registered User
 
Join Date: Feb 2011
Last Activity: 15 February 2014, 7:50 PM EST
Posts: 127
Thanks: 44
Thanked 3 Times in 3 Posts
WOW, nice!
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to check weather a string is like test* or test* ot *test* in if condition johnjerome Shell Programming and Scripting 5 02-18-2010 05:38 AM
Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d Max89 Shell Programming and Scripting 1 11-25-2009 01:08 PM
can't TEST multiple arguments for a file cruiser Shell Programming and Scripting 2 11-22-2005 03:27 PM
Can not test many arguments baton Shell Programming and Scripting 4 11-18-2005 07:12 AM



All times are GMT -4. The time now is 10:17 PM.