Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Test - too many arguments

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 03-28-2011
michaelrozar17's Unix or Linux Image
michaelrozar17 michaelrozar17 is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 23 July 2015, 8:19 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 Unix and Linux 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 09:27 AM.