Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Calling Function from Profile in Shell Script

Calling Function from Profile in Shell Script

I have a function "fnd" in my .profile file. I have shell script calling function "fnd" but it doesn't recognize the file unless I load the .profile file. I don't have to do this when referencing variables in my .profile file but can't get it to work without loading the file for my function. Is there a character I need to use to call a function similar to when I call variables ($)?

function fnd {
if [[ $# = 2 ]]; then
find $1 -type f -exec grep -l "$2" {} \;
export env=system
#!/bin/ksh -f
echo $env
fnd . function

$ ./
./[20]: fnd: not found

RE: Calling Function from Profile in Shell Script

Try "set -ah" right before the function definition. "man set" for more information.

RE: Calling Function from Profile in Shell Script

Thanks for your replies PHV and SamBones.

I tried variations of your recommendations and it still won't work. Again, I can easily avoid this by loading the file containing the function, but we are trying to avoid this. Any help is appreciated.

RE: Calling Function from Profile in Shell Script

I second PHVs suggestion. Also, you can put your functions in a separate script, say shell_functions.ksh, then just source it in the scripts you want to use them in.

CODE --> shell_functions.ksh

function fnd {
if [[ $# = 2 ]]; then
find $1 -type f -exec grep -l "$2" {} \;

CODE --> check.ksh


.  /path/to/shell_functions.ksh

fnd . function 

This will still work when you're using cron to launch it too.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close