Scope of exported function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scope of exported function
# 1  
Old 02-13-2011
Scope of exported function

Hi

I'm hoping someone can tell me how to extend the scope of an exported function in the korn shell.

I have written a function in a file that I dot in from my .kshrc file and it works fine.

However I would like this function to be available to anyone in a certain group on the machine without all of them being required to dot it in, in their own .kshrc files.

Can anyone tell me how to do that?

Thanks in advance
# 2  
Old 02-13-2011
'man ksh' yields:
Code:
  Variables Used by Shell
     The following variables are used by the shell:
   ........
   ........
     FPATH The search path for function definitions. By  default,
           the  FPATH  directories  are  searched  after the PATH
           variable. If an executable file is found, then  it  is
           read and executed in the current environment. FPATH is
           searched before PATH  when  a  function  with  the  -u
           attribute  is  referenced.  The  preset alias autoload
           causes a function with the -u attribute to be created.

# 3  
Old 02-13-2011
By putting the function definition in /etc/profile (or something like), you'll make it system-wide.

If you just want to make it available from a specific group then make an executable script file of it with the appropriate name and starting with the #!ksh shebang.

Do a chown root:<your group> and chmod 754 (or 750) so it will only be executable by root or members of <your group>.

Put it i.e. in /usr/local/bin , it's a good place place for it.
# 4  
Old 02-13-2011
Have read of this from BigAdmin: http://www.sun.com/bigadmin/scripts/...yafunction.txt.

To avoid potential scoping issues, you should use typeset to ensure that variables only have local scope where possible.
# 5  
Old 02-14-2011
Thanks for the replies folks

Unfortunately they don't tell me how to make this available to a group.

I know how to dot in the function within my shell and also how to set the FPATH and so on but these all require potential users to add an entry to their profile or kshrc file. I just thought it would be nicer if any member of a group running ksh could automatically have this available when starting a shell.

I was hoping it might be possible to call a script when a group member starts a session but I don't know if I can.

I'll keep chewing on it.

Cheers
# 6  
Old 02-14-2011

Check the users' group:
Code:
if [ $(id -g) = 666 ] ## adjust to taste
then
  . groupfuncs
fi

# 7  
Old 02-14-2011
Thanks

I think this would still involve an entry in their profile or kshrc though.

I think I'll start another more detailed post about what I am trying to achieve.

Thanks for the input

---------- Post updated at 05:13 PM ---------- Previous update was at 04:56 PM ----------

Now I have the package installing this how I want I can put a lot more detail in here about what I am trying to do: -

I have a two related utilities called push and pop that I have written as exported functions. They allow me to create "stacks" of directories that are presented to the user in the form of menus: -
=============================================================
Current stack is - Packaging
=============================================================
1) /home/brad/spideroak/wip/packaging/pushpop
2) /home/brad/spideroak/wip/packaging/pushpop/debian/DEBIAN
3) /home/brad/spideroak/wip/packaging/pushpop/debian/usr/bin
4) /home/brad/spideroak/wip/packaging/pushpop/debian/usr/share/doc/pushpop
5) /var/cache/man
6) /home/brad/spideroak/wip/man/man1
7) Quit
Please select a directory -

So while I am developing something I can create a stack of all of the directories I am interested in while the development is in progress. Also if I come back to it in a months time I can reload the saved stack and I can immediately see all of the directories that relate to this project.

I thought this would be a nice project to cut my teeth on debian packaging and so I have created a package that installs the files containing the functions and environment vars into /usr/bin and adds a couple of man pages.

To access the functions I put two entries into my kshrc file: -

. /usr/bin/.pp.env
. /usr/bin/.exported.funcs

I think this is the weakness in the package though, I don't like the idea of the end users needing the knowledge of how to do this. I would like the package to take care of all dependencies.

I can't have the package modify everyones kshrc or profile. After all this is specific to korn shell users and anyway people should have the right to opt in rather than have this forced on them.

That is why I was asking about the group idea but am open to any suggestions that allow users to opt in without knowing how to find and edit their profile or kshrc.

I guess in a worst case scenario I could put details on how to enter these in the man pages.

Any ideas greatly appreciated.

---------- Post updated at 05:26 PM ---------- Previous update was at 05:13 PM ----------

Hi Folks

I've been boning up on how to create debian packages and now have a working package. I am still getting warnings though when I run it through lintean: -

Code:
/home/brad/spideroak/wip/packaging/pushpop > lintian pushpop_1.2-1_all.deb
W: pushpop: syntax-error-in-debian-changelog line 5 "found eof where expected first heading"
W: pushpop: binary-without-manpage usr/bin/.exported.funcs
W: pushpop: binary-without-manpage usr/bin/.pp.env

With regard to the errors about binaries without man pages. These are two files: one containing environment vars and the other some exported functions. The directory structure used to create the package is: -

Code:
./debian
./debian/usr
./debian/usr/bin
./debian/usr/bin/.pp.env
./debian/usr/bin/.exported.funcs
./debian/usr/share
./debian/usr/share/doc
./debian/usr/share/doc/pushpop
./debian/usr/share/doc/pushpop/copyright
./debian/usr/share/doc/pushpop/changelog.Debian.gz
./debian/usr/share/man
./debian/usr/share/man/man1
./debian/usr/share/man/man1/push.1.gz
./debian/usr/share/man/man1/pop.1.gz
./debian/DEBIAN
./debian/DEBIAN/control

How can I get rid of these warnings as I don't want man pages for the files. My man pages refer to the internal exported functions.


With regard to the warning: -

Code:
W: pushpop: syntax-error-in-debian-changelog line 5 "found eof where expected first heading"

I've been reading tutorials all day on this but can't seem to bottom out what it wants. Here is the file: -

Code:
pushpop (1.2-1) urgency=low

  * Made Debian package lintian clean.

 -- maintainer Bradley Atkins <info@bradleyatkins.com>  Sun, 13 Feb 2011 22:00:00 +0000

I think their should be a field between the name (version) and the urgency field. But the line it is complaining about is the last line.

Any ideas or insights are welcome
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Loading associative array from exported function

Hello. I have an export of an associative array build using declare -p SOME_ARRAY_NAME > SOME_FILE_NAME.txt. Producing some thing like declare -A SOME_ARRAY_NAME=( ="some_text" ="a_text" ......... ="another_text" ) in a text file. I have a stock of functions which are sourced from... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Beginners Questions & Answers

Sudo has no access to exported bash function

Hello. I am running leap 15.1 sudo behavior may differ from other distrib. I have a file with functions definition .... function_1 { echo "Hello world" } export -f function_1 This file is sourced by both /etc/bash.bashrc.local and profile.local. So the functions are... (3 Replies)
Discussion started by: jcdole
3 Replies

3. Shell Programming and Scripting

BASH: variable and function scope and subscripts

Hi, I'm a Delphi developer new to linux, new to this forums and new to BASH programming and got a new task in my work: maintaining an existing set of BASH scripts. First thing I want to do is making the code more reliable as in my opinion it's really bad written. So here's the quest: I'm... (6 Replies)
Discussion started by: rse
6 Replies

4. Shell Programming and Scripting

Use of exported variable

i have to use the exported variable from one script into another script ex : A.ksh # !/bin/ksh chk1=56 export chk1 B.ksh # !/bin/ksh echo $chk1 i have executed the... (6 Replies)
Discussion started by: urfrnddpk
6 Replies

5. AIX

exported filesystems on a NIM server

I have a filesystem that was exported sometime in the past, probably by NIM processes, but cannot be unexported now. How can I get rid of this? Any ideas? I tried rebooting and it survived it. hostname:/:$ exportfs -v /usr/lpp/bos.sysmgt/nim/methods... (2 Replies)
Discussion started by: kah00na
2 Replies

6. Shell Programming and Scripting

using the exported variable after su

Dear All,How can use a variable which I have exported when I am logged into one user to be used once I su to another user.something like 1.Login to Unix box as user12. export var1="TEST"3. su - user24. User the var1 value ( it should return TEST)I have checked just export does not work. any other... (1 Reply)
Discussion started by: rahulkav
1 Replies

7. Shell Programming and Scripting

Seeing variable which are exported with export

Greeting to all of you! I've small issue related to the variable which we are setting and exporting through scripts, in one of the script there are some variable used but I am not abel to get the detail as where they are set. I tried finding the detail with the help of env but no luck. ... (2 Replies)
Discussion started by: kumarmani
2 Replies

8. Solaris

Remove the exported zpool

I had a pool which was exported and due to some issues on my SAN i was never able to import it again. Can anyone tell me how can i destroy the exported pool to free up the LUN. I tried to create a new pool on the same pool but it gives me following error # zpool create emcpool4 emcpower0c... (0 Replies)
Discussion started by: fugitive
0 Replies

9. Linux

Can USB Devices Be Exported Over a Network?

While I know that it's possible to use something like SANE to share a USB scanner over a network, or use NBD or iSCSI to share a USB flash or external HD over the network, I've been wondering about a raw USB <--> TCP/IP transport. Back in the late 90s, I swear I remember hearing about a project... (2 Replies)
Discussion started by: deckard
2 Replies

10. Shell Programming and Scripting

$0 scope in function and calling script

Hi folks, I'm just running through an oreilly korn shell book but have witnessed an output difference on my own unix machine and the output provided in the book. Can anyone help? create a script called ascript as follows: function afunc { print in function $0: $1 $2 var1="in... (16 Replies)
Discussion started by: beckett
16 Replies
Login or Register to Ask a Question