default function in shell scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting default function in shell scripts
# 1  
Old 07-19-2012
default function in shell scripts

Hi,

Are their any default functions which can be written in a shell script to add new behavior.

May be I want to do something before the shell script starts and something which I would like to do at the end of script.
# 2  
Old 07-19-2012
You can write as many functions as you want. Things that are being needed often with a great value of reuse.
Just write them as function in a separate file and in the main script, "source" them by
Code:
. /some/dir/_my_math.lib

for example.
So all functions defined in _my_math.lib will be recognized in the main script. Works like an include.

Last edited by zaxxon; 07-19-2012 at 04:09 PM.. Reason: spelling
# 3  
Old 07-19-2012
I am doing the same. using a file as library with a lot of useful function.

I was trying to find if any specific function is invoked by shell itself either at start up or during exit.

For example, at the end of script, I want to cleanup specific temp dir.
Today I have to call the cleanup function at the end of every script. I want to avoid doing this.
This make me think if shell can provide me a hook function which I can implement in this library which does the cleanup job.

Hope I could communicate my requirement ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Default shell for executing scripts

Hi there, And happy new year to everyone. I was wondering how is set the default shell for executing scripts. I mean when the first line of a script file is not #!/bin/bashThen what shell will be used to execute the script? I thought the script file would be parsed using the current shell... (6 Replies)
Discussion started by: chebarbudo
6 Replies

2. Red Hat

how to call a particular function from one shell another shell script

please help me in this script shell script :1 *********** >cat file1.sh #!/bin/bash echo "this is first file" function var() { a=10 b=11 } function var_1() { c=12 d=13 (2 Replies)
Discussion started by: ponmuthu
2 Replies

3. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

4. Shell Programming and Scripting

isset() PHP function in cgi bash scripts

Hi! Some minutes ago I've posted a question related with sed regexps because I need to catch information sended with forms with GET action. This is the post: https://www.unix.com/shell-programming-scripting/127800-regular-expression-sed.html But now I have a new question. Does cgi scripts have... (0 Replies)
Discussion started by: GagleKas
0 Replies

5. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

6. HP-UX

Shell Scripts

I have a text file . Format of text file. djss:xd:78:isdev:"test server" this type of row. (approx 30). I want to display like that 1. djjs@msxd testserver 2. xjfd@msxd devserver 3. 4 select any one from above choice : 1... (5 Replies)
Discussion started by: rastogideepak
5 Replies

7. AIX

Shell Scripts

I would like to seek some expertise of all our AIX experts on board. 1) I would like know how to get a return exit code of a command. I found that there are exist code for each and every command run in AIX but I just can't get the return code from my scripts. A=`cp /home/abc/abc.txt... (7 Replies)
Discussion started by: kwliew999
7 Replies

8. Shell Programming and Scripting

Help With Shell Scripts

if I run the below mentioned code, i am getting error. I dunno why. plz help me out this code runs a sql query and sends the result by email #!/bin/ksh # # Purpose: - Report Workflows that have Persistence turned ON echo "Workflow Persistence Report Started: `date '+%Y%m%d_%H%M%S'`" >>... (6 Replies)
Discussion started by: ragha81
6 Replies

9. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

10. UNIX for Dummies Questions & Answers

about shell scripts

Hi, i have made a script which makes some analyses on some differnet hosts. but i have a problem to make this script more quicker ... i would like to enter more a one hosts in the query (in my script are this: Pls enter the Hostname ... read hostname for i in $hostname do echo... (5 Replies)
Discussion started by: scottl
5 Replies
Login or Register to Ask a Question