Fedora Linux Support Community & Resources Center
  #1  
Old 10th March 2008, 10:51 AM
theory Offline
Registered User
 
Join Date: Mar 2008
Location: Copenhagen, Denmark
Posts: 4
Check if parameter is NULL (shell scripting)

Hello,

Im really new to shell scripting and I'm trying to make a recursive algorithm, but I'm having difficulty in making a check to see wether a parameter has a value or not.


Code:
if [ $1 -eq NULL ] && [ $2 -eq NULL ]
then
echo "Parameters doesn't have a value ($1 and $2)"

else echo "$1 and $2 has a value or check failed"
exit 1
fi
Btw, im guessing theres differences when writing to a Kourne or Bash shell. I'd like it to work under ksh, but if it can only be done under bash then fine! :-)

Cheers in advance
Reply With Quote
  #2  
Old 10th March 2008, 11:00 AM
BlueC Offline
Registered User
 
Join Date: Aug 2007
Location: Liverpool, UK
Posts: 733
perhaps....

Code:
if [ -n "$1" ] && [ -n "$2" ] # note the quoted test strings
then
  echo "Strings \"$1\" and \"$2\" are not null."
else  
  echo "Strings \"$1\" and \"$2\" are null."
fi
alternatively:

Code:
if [ $1 ] && [ $2 ]
then
  echo "Strings \"$1\" and \"$2\" are not null."
else  
  echo "Strings \"$1\" and \"$2\" are null."
fi
For more see http://tldp.org/LDP/abs/html/comparison-ops.html

HTH

Last edited by BlueC; 10th March 2008 at 11:04 AM.
Reply With Quote
  #3  
Old 10th March 2008, 11:58 AM
theory Offline
Registered User
 
Join Date: Mar 2008
Location: Copenhagen, Denmark
Posts: 4
They both work.

Thank you very much :-)
Reply With Quote
Reply

Tags
check, null, parameter, scripting, shell

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
shell scripting - please need help malaka19 Using Fedora 4 20th January 2008 03:18 PM
shell scripting haaidy Programming & Packaging 5 14th January 2008 10:42 PM
shell scripting Baby Chen Programming & Packaging 32 11th February 2006 06:46 PM
shell scripting jim Programming & Packaging 8 10th May 2005 05:18 PM


Current GMT-time: 17:12 (Wednesday, 30-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat