Date: Sat, 17 Nov 2001 01:22:11 -0500 From: Garance A Drosihn <drosih@rpi.edu> To: Rod Person <roddierod@yahoo.com>, FreeBSD Questions <freebsd-questions@FreeBSD.ORG> Subject: Re: bash script function errors Message-ID: <p05101000b81bb0679adc@[128.113.24.47]> In-Reply-To: <20011116192217.027e7a84.roddierod@yahoo.com> References: <20011116192217.027e7a84.roddierod@yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
At 7:22 PM -0500 11/16/01, Rod Person wrote: >I'm trying to run a bash script that contains functions. when I run >the script I get the error that the function in the script is not >found? How do I correct this? Do I have to place the directory that >the script is in in the path variable? I try to invoke the script >like this sh ./script.sh While we'd like to help, it is not clear what exactly your problem is, as you haven't described it in quite enough detail. It is not clear what you are trying to do, and it is not clear where you are getting the error. Are you defining the function within the script, and also trying to use the function within that same script? If so, we need to see more of the actual script to guess at what might be wrong. If it is a large script, then try to do "something similar" but on a much smaller scale, and see if that works. If it does not, then you would have something small enough to post. Are you defining the function within some script, and then trying to reference that function AFTER the script has completed? If so, well, you can not do that. When you execute a script, it runs as a separate process, and that separate process can not change the environment of the process you are running it from. ("change the environment" in the sense of "adding a new function to that environment"). So, your script will define the function, but that function is only available inside of that script. If that is the case, then you want to look into the 'source' command. The source command will read the file, and process each line of the file as if you typed it within the shell. Be a little careful when doing this, because if your file includes a command like 'exit' (which would make sense for a script), that command will be executed in your *active* shell, and the shell you are typing into will go right ahead and exit. -- Garance Alistair Drosehn = gad@eclipse.acs.rpi.edu Senior Systems Programmer or gad@freebsd.org Rensselaer Polytechnic Institute or drosih@rpi.edu To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?p05101000b81bb0679adc>