The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
using awk != parameter karthikn7974 Shell Programming and Scripting 4 04-28-2008 07:59 AM
checking parameter values passed to script ammu UNIX for Dummies Questions & Answers 2 10-05-2007 01:35 PM
how do I make dynamic parameter names? Or get the value of a parameter evaluated twi Awanka Shell Programming and Scripting 2 04-19-2007 10:37 PM
parameter u263066 Shell Programming and Scripting 5 10-12-2006 04:46 AM
$- parameter ... moxxx68 UNIX for Dummies Questions & Answers 2 02-10-2005 07:23 PM

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-23-2007
ammu ammu is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 79
Parameter Checking

Hi all,

My script has 2 mandatory and 1 optional paramter. If the third parameter(optional) one is null the it should take a default value say 3. Can any one please write a simple code.

sh test.sh 1 2 3

var1=$1
var2=$2

if [ -z $3 ]
then
var3=3
fi

echo " the third variable $var3"

But this is erroring out saying " test.sh: test: argument expected"

Thanks in advance
Ammu
  #2 (permalink)  
Old 05-23-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,423
Code:
var1=$1
var2=$2

if [ -z "$3" ]
then
var3=3
fi

echo " the third variable $var3"
or
Code:
var1=$1
var2=$2
var3=${var3:-3}
echo " the third variable $var3"
Jean-Pierre.
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 06:26 AM.


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