Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unix fu nction

Status
Not open for further replies.

bhas1

Programmer
Mar 17, 2007
4
US
Can you please help with unix functions. I am usin bash sell I have a function called run_cmd written and saved in a separate file and I need to call this function in my shell script I just tryied with function name run_cmd it gives me error run_cmd not found.. Any help is appriciated..
Thanks,
BK
 
Have a look at the . (dot) or source command.
I don't know for bash, but with ksh you may play with the ENV environment variable.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Try

Load=$( </full/path/run_cmd)

Load otherstuff





Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
Mike,
Thank you for replay,
sorry, I did not get it. like load=$(</full/path/run_cmd)
you mean when ever i want to use function I need to specify $load and paramters of the function?

Thanks
 
There are two things which catch out Unix newbies running scripts, especialy those who are converts from Windows.

The first is that the default path, unlike Windows, does not include the current directory. There are a number of ways you can run scripts in your current directory
[ol]
[li]Add the current directory to your PATH using
Code:
PATH=$PATH:.
- this is not recommended, there's a good reason it wasn't there in the first place[/li]
[li]Use the path, i.e
Code:
./run_cmd
[/li]
[li]Run the command as a parameter to bash, i.e
Code:
 bash run_cmd
[/li]
[li]That will do for now[/li]
[/ol]

The other thing that tends to get forgotten is permissions. If you created the file with the standard permissions then you won't be able to run it. The command '
Code:
chmod 755 run_cmd
' will fix that.

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top