1837896 Members
3359 Online
110122 Solutions
New Discussion

Unix Function

 
intp
Frequent Advisor

Unix Function

can someone send me sample code for creating unix shell script function? like global variables (defined in . profile file) ...can we
create a function globally and use within any shell script and /or in shell command prompt itself ? if yes , any sample code will be great...

sorry for too many questions...i'm new to shell scripting and too many tasks on my plate. appreciate all your patience and helps.
2 REPLIES 2
Olivier Masse
Honored Contributor

Re: Unix Function

Add this to .profile:

foo()
{
echo "This is a sample function that runs the id command"

id
}

Anybody can now run foo as if is was a command. As an alternate, you can also make an alias:

alias ls="ls -al"


James R. Ferguson
Acclaimed Contributor

Re: Unix Function

Hi:

A good discussion, but simple and concise, overview of various shells can be found in the document below. I suggest you confine your initial reading to the Posix shell. After all, this is the default shell on HP-UX and the one that is required for 'root' and for startup scripts. There is a discrete section on functions, too:

http://docs.hp.com/en/B2355-90046/index.html

Regards!

...JRF...