How to make parameters optional?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make parameters optional?
# 1  
Old 05-23-2008
How to make parameters optional?

Hi,
I am trying to call a function inside a shell script. Is there a way in which I can make the parameters options in the call?
Please help me with this.
Thanks!!!
# 2  
Old 05-23-2008
There are different ways to interpret your question.

is it possible for you to elaborate or describe an example of what you want?
# 3  
Old 05-24-2008
One possibility...
Code:
#! /bin/sh
#
func1()
{
 banner $1
}

func1 testing

Is this you want?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getopts with optional parameters

Hi Unix Gurus, i am on learning path of unix, and yet to discover many things. I came across with this requirement where i need to pass parameters but the position of parameters is not fixed so after doing some google search got to know "getopts" can handle that. So here is my code: function... (3 Replies)
Discussion started by: gnnsprapa
3 Replies

2. Red Hat

Linux Optional Packages

Please forgive but I am new to Linux and still learning. When installing Linux (any flavor) over PXE, it asks if you want to customize which packages to install. Most engineers ask us to install all packages but this entails A LOT of clicking. Is there a way to "select all" packages by using a... (3 Replies)
Discussion started by: svolbruck
3 Replies

3. Shell Programming and Scripting

Read Parameters from one file and make a script

Hi Friends, I have the following input parameters file name input err1 out1 1 40G DET sylamer dir1 dir2 123456 I want to make the following script #!/bin/bash # (5 Replies)
Discussion started by: jacobs.smith
5 Replies

4. Shell Programming and Scripting

How to make shell script arguments optional?

Here is my script: #!/bin/ksh usage () { echo " Usage: $0 <opt1> <opt2> <opt3> <opt4>" } if ; then usage exit; fi prog -a $1 -b $2 -c $3 -d $4 2>&1 | tee -a ~/$1.log I want argument 4 to be optional, so if there's no argument for opt4, that it doesn't... (8 Replies)
Discussion started by: guitarscn
8 Replies

5. Shell Programming and Scripting

Two arguments for optional switch

How to declare the two argument for optional switch ? I have a script that search for a string in current or old zipped log file. Im using a option something like this ${basename} Since $1 can have only one argument should be passed when user select swicth -c and -o need to... (3 Replies)
Discussion started by: baraghun
3 Replies

6. Shell Programming and Scripting

getopts - optional and problem to display help

In the below code while getopts :rfw:d:s:a: options do case "$options" in r) echo reverse;; f) echo forward;; w) window=$OPTARG;; d) duration=$OPTARG;; s) search=$OPTARG;; a) value=$OPTARG;; *) help; exit;; esac done ... (2 Replies)
Discussion started by: Amutha
2 Replies

7. Shell Programming and Scripting

Optional Parameters/arguments while executing a script.

Hello, I have a shell script "Test.ksh" and I need to pass 8 parameters/arguments while executing the script ./Test.ksh 1 2 3 4 5 6 7 8 Out of these I want first 3 to be compulsory and rest 5 to be optional. Can you suggest the way to do this like and also how to pass these optional... (3 Replies)
Discussion started by: indrajit_u
3 Replies

8. AIX

tuning network parameters : parameters not persist after reboot

Hello, On Aix 5.2, we changed the parameters tcp_keepinit, tcp_keepintvl and tcp_keepidle with the no command. tunrestore -R is present in inittab in the directory /etc/tunables we can clearly see the inclusion of parameters during reboot, including the file lastboot.log ... (0 Replies)
Discussion started by: dantares
0 Replies

9. Shell Programming and Scripting

grep with regular expression optional value

field 12345 12345 field 12345 field 12345 123456 last fleld (from three) is optional, but if it occures It has to be composed only of nummbers and maximum 5 positions long. If I use: grep "^field \{5\}" I get: field 12345 12345 field 12345 field 12345 123456 But I wont... (11 Replies)
Discussion started by: necroman08
11 Replies

10. Programming

Optional non-const reference argument c++ ?

Is it possible to have a non-const reference variable as an OPTIONAL/DEFAULT parameter to c++ function ex void read(string &data,int &type=0 /*or something*/) ; so i will call read(data); //or int type; read(data,type); printf("Type =%d",type); I found one dirty workaround ... (2 Replies)
Discussion started by: johnbach
2 Replies
Login or Register to Ask a Question