bash script function parameters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash script function parameters
# 1  
Old 12-05-2010
bash script function parameters

I have a question about bash script.

Can I create a function there that accept parameters like functions in program language?
# 2  
Old 12-05-2010
Yes you don't actually put them in the functions header, but you can look at each parameter giving to a function the same way you look at shell parameters. The parameters start with $1, $2... and so on.
This User Gave Thanks to codecaine For This Post:
# 3  
Old 12-05-2010
Yes, call by value. And you can emulate call by reference, but usually you do not need that and just capture the output of the function..
This User Gave Thanks to Scrutinizer For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script: problem with a function which use colors

Hello guys :) I've a some issue with a function which use the bash colors in my script. An example : #!/bin/bash set -x log_in(){ host="srv1" remote_files="log/" LOG_FILE="logfile" green='\033]; then color_in_red=("${red}"$2"${none}") echo -e... (2 Replies)
Discussion started by: Arnaudh78
2 Replies

2. Shell Programming and Scripting

How to call a bash script with positional parameters?

Hi, I have a script which will be executed using the below command, bin/nutch crawl urls -dir /data/test/ bin/nutch - Script file crawl, urls, /data/test/ - Parameters -dir - Option The above script should executed from a shell script named test.sh. I have the below code to execute... (2 Replies)
Discussion started by: vel4ever
2 Replies

3. Shell Programming and Scripting

Bash- Command run from script does not pass full parameters with spaces inside

There's a JavaScript file that I call from command line (there's a framework) like so: ./RunDiag.js param1:'string one here' param2:'string two here' I have a shell script where I invoke the above command. I can run it in a script as simple as this #!/bin/bash stuff="./RunDiag.js... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

4. Shell Programming and Scripting

Calling function from another bash script

I would like to call functions from another bash script. How can I do it? Some code More code (11 Replies)
Discussion started by: kristinu
11 Replies

5. Shell Programming and Scripting

Passing parameters to bash script function (or subroutine)

I've found a few posts regarding passing parameters to a function or subroutine, but for some reason when I try to run a command based on part with these parameters it's not working. If I have the function echo the parameters they show correctly so I believe they are being passed right but the... (2 Replies)
Discussion started by: withanh
2 Replies

6. Shell Programming and Scripting

Help with grep and read function in a BASH Script

I'm putting together a script that will search my mail archives for emails that meet certain criteria and output the files to a text file. I can manually cat that text file and pipe it into sendmail and it will work (i.e. cat /pathtofile/foo.txt | sendmail -t me@company.com) My script sends... (7 Replies)
Discussion started by: binary-ninja
7 Replies

7. Shell Programming and Scripting

error when call function in bash script

Dear all, Could you please advice as I when call function i found the following error " refills: command not found" note that refills is function name. following also the function and how i call it function refills { echo "formatting refills and telepin" >> $log awk -F,... (20 Replies)
Discussion started by: ahmed.gad
20 Replies

8. Shell Programming and Scripting

Parameters for function in Shell script

Hi, I am having a function inside a shell script. The Shell script is called with parameters and one of the parameter is passed to a SQL script inside the function. But when the function is called inside the shell script, the SQL script is not called. Do the shell parameter has to be... (3 Replies)
Discussion started by: srimenon09
3 Replies

9. Shell Programming and Scripting

Run function from script over ssh (BASH)

Hi, Is there any cleaver way to run function from the bash scrip over ssh? For example: #!/bin/bash #Function 1 FN1 () { ls -l } #Main run ssh user@host FN1 exit 0 Yeah, I know it will not work, but I'm asking how to make it to work :) I'm suspecting that it would be... (1 Reply)
Discussion started by: columb
1 Replies

10. UNIX for Dummies Questions & Answers

Easy About Bash Script function

Hi to all, first of all,i am working on MINIX 3 OS. I want to create a bash script file,which will create a list of files(not directories) that have been modified one specific day (i.e today) under my home directory. thank you very much!! :) (8 Replies)
Discussion started by: kostis1904
8 Replies
Login or Register to Ask a Question