How to get the text of a single shell function?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get the text of a single shell function?
# 8  
Old 01-13-2010
Simple in what way? If anyone but you has to touch the internals of that script at all ever again, they'll understand "source filename", but may need to dig for hours or days to understand what your objective with set is and why it's suddenly not working. Build something too clever and you might return to it in a year to find you have no idea what you were thinking.

Another way to do a remote script without copying files to the servers would be 'ssh servername < script-file'. Either way though, it's just better to have the function stored in a way you can use it than try to rip it out from inside the shell.

You could also try making the script a here-document, saving it to a temporary file, sourcing it, and sending it on from there. self-contained. You'll find yourself banging your head against the wall having to escape every little thing inside the here-document to make it work though.

or you could send the entire script itself through ssh: 'ssh servername < "$0"', providing your script's written in a way it can tolerate that and not recur infinitely.

Last edited by Corona688; 01-13-2010 at 07:01 PM..
# 9  
Old 01-13-2010
Code:
typeset -f function_name

Should work in bash, ksh, and pdksh, if i'm not mistaken.

Regards,
alister
# 10  
Old 01-13-2010
Thanks. That looks like just what I was looking for. Of course, as Corona688 pointed out I may have to consider whether I'm getting too clever. It doesn't seem so, but it wouldn't have been the first time. Smilie

Thanks again to everyone for your input, especially those of you in Europe. It's got to be after midnight there! Smilie

Mark E. Hamilton

Last edited by MarkHamilton; 01-13-2010 at 08:05 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

A single statement without main function in c

A sample.c file is written with only one single statement. main; Segmentation fault occurred when executed that file. Any statement other than main; is written, for example unix; then it won't compile. why is this behaviour ! (2 Replies)
Discussion started by: techmonk
2 Replies

2. Shell Programming and Scripting

Avoid single line output from function

I am new to shell scripting and wished to get few things clarified. While calling functions within shell script, output comes out as single line irrespective of the no of echos or newlines I tried within function + the echo -e used to invoke function ( as instructed online) : #!/bin/sh inc() {... (1 Reply)
Discussion started by: RMath
1 Replies

3. Shell Programming and Scripting

Induct two functions in a single function

echo -en "Enter the logmsg=" {D1234,S1234 | rohit singh} read logmsg logmsg1=${logmsg%%|*}; echo $logmsg1 |sed "s/$/,/g"|sed 's/*$//'>pre-commit.config logmsg_len2=$(echo ${logmsg} | awk '{print $2}'); logmsg_suffix="|"; length() { cat "pre-commit.config"| awk -F'' '{for(i=1;i<NF;i++) {... (6 Replies)
Discussion started by: rohit22hamirpur
6 Replies

4. UNIX for Dummies Questions & Answers

extract text between two words on a single line

Hi Guys, Can someone help me with a way to extract text between two words on a single line. For example if the file has below content I want to extract all text between b and f inclusive of b and f. Aparently sed does this but does it line by line and I guess it cannot read word by word. ... (11 Replies)
Discussion started by: krishnaux
11 Replies

5. UNIX for Dummies Questions & Answers

appending in a single text file

actually, i have to grep the value of cpu usage from six differrent servers and it has to generated in a single report( in a single text or excel file). i have used the below command for grepping the value. top -n 1 > arun.txt cat arun.txt | grep 'init' | cut -c 49-53 > output1.csv like... (2 Replies)
Discussion started by: arunmanas
2 Replies

6. 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

7. Shell Programming and Scripting

Create multiple text file from a single text file on AIX

Hi I need to create multiple text files from onc text file on AIX. The data of text files is as below: ********************************************** ********************************************** DBVERIFY: Release 10.2.0.4.0 - Production on Tue Nov 10 13:45:42 2009 Copyright (c) 1982,... (11 Replies)
Discussion started by: lodhi1978
11 Replies

8. Shell Programming and Scripting

Awk problem: How to express the single quote(') by using awk print function

Actually I got a list of file end with *.txt I want to use the same command apply to all the *.txt Thus I try to find out the fastest way to write those same command in a script and then want to let them run automatics. For example: I got the file below: file1.txt file2.txt file3.txt... (4 Replies)
Discussion started by: patrick87
4 Replies

9. Shell Programming and Scripting

Call single function multiple times diff set of parameters

Okay, not sure if it can be done, I would think it could be done and I'm just having a hard time with it. fun_close_wait(){ ipVar="${1} ${2}" portVar=`cat "${5}" | cut -d' ' -f 1` for ip in $ipVar do for port in $portVar do netstatVar=`netstat -n | grep... (4 Replies)
Discussion started by: cbo0485
4 Replies

10. Shell Programming and Scripting

Have several text files and want to merge into a single

Hello, I have several files that begin with db. in my directory and I would like to first take it from a specific word starting from $TTL until the end of the contents then do the same all the way down the directory then merge them into one txt file. Is this possible? I am using cygwin with... (4 Replies)
Discussion started by: richsark
4 Replies
Login or Register to Ask a Question