bash functions arguments


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash functions arguments
# 1  
Old 09-16-2009
bash functions arguments

This script is called fuu;

Code:
#!/bin/bash

speak() {
        case $1 in
                1)echo one
                ;;
                2)echo two
                ;;
                3)echo three
                ;;
        esac
}

speak

exit 0

when i run fuu 2 i expect "two" like result and i get nothing.

Please, What i'm doing wrong?
# 2  
Old 09-16-2009
Code:
speak "${1}"

# 3  
Old 09-16-2009
Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash functions sequence ?

OK, I know function has to be defined first - in sequence - before it can be used. So the script has to be build "bottoms -up style, if you pardon my expression. I am running into a problem reusing function and breaking the sequence. It would be nice to be able to see the function... (10 Replies)
Discussion started by: annacreek
10 Replies

2. Shell Programming and Scripting

Bash calling a few functions syntax error

In the bash function below if the user selets "y" then the menu function is called and if they select "n" the move function is called. That all seems to work, my question is after the files are moved an echo, line in bold is displayed and another function called backup is called. I am getting a... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. Shell Programming and Scripting

Calling Bash Functions in the BG

I'm trying to call some functions in the background so that I can multitask in this script. Not working so hot. The functions I call don't ever seem to get called. I'm doing it the exact same way in another script and it's working like a champ so I'm very confused. Here's a pretty simple repro: ... (7 Replies)
Discussion started by: stonkers
7 Replies

4. Shell Programming and Scripting

functions and variables in bash

I have a bash script with some functions as below and am wondering if I can use the variables declared in setup in the other functions and in the rest of the bash script. setup(){ none=0; low=1; medium=2; high=3; debug=4 var1="red" var2="fred" } create_basemap() { ... (7 Replies)
Discussion started by: kristinu
7 Replies

5. Homework & Coursework Questions

Understanding Functions, sh, and arguments

1. The problem statement, all variables and given/known data: So I have to write a Bourne script that will add two numbers, taking only two arguments and informs the user when it is used incorrectly. 2. Relevant commands, code, scripts, algorithms: It has to be done in sh. I think overall,... (3 Replies)
Discussion started by: lee.n.doan
3 Replies

6. Shell Programming and Scripting

importing functions from an external bash script

Hi all, I'm trying to import some functions I have saved in a file named functions.sh into a different script (protocol.sh). Can anybody show me how to do this? I tried source functions.sh as I would do at the terminal but source command cannot be found from within the script protocol.sh. ... (2 Replies)
Discussion started by: tevang
2 Replies

7. Shell Programming and Scripting

Functions, exit, and kill in bash

Hello Okay, for reasons related to sourcing a script from another script, I've had to put my main loop into a function, and from there I call other functions. My problem then is exiting from deep within the function call stack. I used to simply call exit, and that would accomplish what I... (1 Reply)
Discussion started by: brsett
1 Replies

8. Shell Programming and Scripting

Mathematical functions in bash shell

Hi, How can i do the mathematical calculations in bash shell? Are the mathematical functions available in bash shell? Ex: pow ceil floor sqrt (5 Replies)
Discussion started by: cola
5 Replies

9. Shell Programming and Scripting

[bash] reassigning referenced variables in functions

Hello all, Problem. ---------- I'm trying to reassign a referenced variable passed to a 'local' variable in a function but the local variable refuses to be assigned the content of the referenced variable. Any ideas would be appreciated. Objective. ----------- Eliminate all $VAR... (1 Reply)
Discussion started by: ASGR
1 Replies

10. Shell Programming and Scripting

Bash: Nested functions and including other scripts

Hello. I have the following problem with bash code: function fl1_load_modules_and_get_list() ........... for module in $FL_MODULES_TO_PROCESS do source "${FL_MODULE_DIR}/${module}/module.sh" done ........... } function fl1_handle_install { local... (12 Replies)
Discussion started by: FractalizeR
12 Replies
Login or Register to Ask a Question