Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-25-2004, 09:52 AM   #1
Registered: Mar 2003
Location: Malaysia
Posts: 63

Rep: Reputation: 15
How to change parameter values of a function in shell script?

Hi all,
I am writing a shell script program that contains a function. I have two inquires related the function, as follows:

1- I am passing a number of parameters to a function, so is it possible to change the values of the parameters from within the function and return back to the main program for further processing?

2- Can I return a specific value from the function name, I mean by using the return keyword from inside the function to return a value to the main program

the code for example:


#! /bin/bash

function callname ()
echo "hello $1"
echo "hello $2"

#change the value of the first parameter for further
#processing in the main program

#the value 55 to be returned to the main program
return 55

echo -e "$name\n"

#here the function should be lunched and the value 55 should be displayed
echo callname $name Farah

#Displaying the contents of the first paramete after it has changed from within the #function itself
echo -e "$name\n"

echo -e "End of program\n"



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass command-line parameter to shell script? Kropotkin Linux - Newbie 12 07-25-2011 09:24 AM
can a C function return value to Shell Script variable yarnar Programming 17 06-02-2010 05:54 PM
Change parameter of /etc/sysconfig/network with a script philipina Linux - Hardware 1 03-11-2004 12:59 PM
Change parameter of /etc/sysconfig/network with a script philipina Linux - General 3 03-11-2004 05:05 AM
How to change function parameter value and return back to the main shell program Bassam Linux - General 1 01-26-2004 10:02 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:41 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration