[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Shell script function problems



phillinux wrote:

I'm trying to write a bash shell script to create user accounts that calls 2 functions. I can't call these functions from the script or the command line. The set command seems to show the loaded script in the shell (loaded with . FunctionName at command line) with other environmental variables. ALSO: The type command does not recognize the function.


The script and functions work on my laptop running Fedora (with one small glitch). Is there something I can do to my Debian server to get functions recognized??


From some other comments in the thread, it sounds like you are trying
to do something like the following:


$ cat foo

g()
{
        printf 'in g\n'
}
$ cat bar
#!/bin/sh

g
$ . foo
$ ./bar # won't work since bar doesn't source foo
./bar: line 3: g: command not found
$ cat baz
#!/bin/sh

. foo
g
$ ./baz
in g


If you source the file with the function definitions, it makes
the functions available in the current shell, but not in subshells
that you may invoke.


Reply to: