Bash function


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash function
# 1  
Old 12-20-2012
Bash function

Code:
startvm()
{
   startguest
}

Is there a way use one line to get this ? actually I want startvm=startguest
# 2  
Old 12-20-2012
Your question is not so clear. But I guess what you need is an alias:-
Code:
alias startvm='startguest'

# 3  
Old 12-20-2012
Quote:
Originally Posted by bipinajith
Your question is not so clear. But I guess what you need is an alias:-
Code:
alias startvm='startguest'

It doesn't work

Code:
#!/bin/bash
xx()
{
        echo "xx"

}

alias yy='xx'
yy

It will report

Code:
./xx.sh: line 9: yy: command not found

# 4  
Old 12-20-2012
Oh I got now what you are asking. You can use eval for this:
Code:
#!/bin/bash
xx()
{
    echo "xx"
}
yy=xx
eval $yy

# 5  
Old 12-20-2012
Quote:
Originally Posted by bipinajith
Oh I got now what you are asking. You can use eval for this:
Code:
#!/bin/bash
xx()
{
    echo "xx"
}
yy=xx
eval $yy

Thanks, if alias work that's perfect
I have a script is
Code:
xx()
{
something
}
zz()
{
something 
}

main()
{
aa
bb
xx
}

in another script I want to call "main" BUT, the xx I want to be zz, and don't want to change main() function anything, here you are use eval $xx
# 6  
Old 12-20-2012
Just out of curiosity... what are you trying to achieve here!!

why don't you call these functions as it is?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash function problem

I am trying to figure out why I am having a "problem" with some functions in a bash script I am running. The reason for air quoting is that the functions are working, they are just not displaying anything to screen when called from another function. Here's an example: function Create_Input {... (6 Replies)
Discussion started by: dagamier
6 Replies

2. Shell Programming and Scripting

Bash function, for BSD

I am putting this thread to shell-threads, because it is about how to make a function work properly. I need a hint for declaring a function right, it has been more than a year I did not work that straight with bash. So my aim is to turn off the eth0 (as it would be in linux, and bge0 in bsd ),... (2 Replies)
Discussion started by: 1in10
2 Replies

3. Shell Programming and Scripting

Yes or No selection within bash function

I need to add a selection within the bash function below and am having some trouble doing so. phox2b() { printf "\n\n" printf "What is the id of the patient getting Phox2B analysis : "; read id printf "Is this an intronic variant? Y/N "; read match_choice case... (5 Replies)
Discussion started by: cmccabe
5 Replies

4. UNIX for Dummies Questions & Answers

Bash INKEY$ function...

This is probably common knowledge to the professionals but not so much for amateurs like myself. This is a code snippet for the equivalent of BASIC's... LET char$=INKEY$ As the timeout parameter cannot be less than 1 second then this is the only limitation... It is a single line... (5 Replies)
Discussion started by: wisecracker
5 Replies

5. Shell Programming and Scripting

BASH function error

Hey everyone. I am currently testing my first function based BASH script. The ultimate goal is going to be moving logs from point A to point B (or if B is down, to point C). Part of this involves the following function: function testAlive{ ping -c 1 -q $1 } Now when I run ping -c... (1 Reply)
Discussion started by: msarro
1 Replies

6. Shell Programming and Scripting

In bash getting weird output from function ?

My script- result="" times() { echo "inside the times function" result=8 echo "Inside function $result" return $result } result=$(times) echo "the value is "$? echo "the value of result $result" when I run I get this, why the value still remain 0. $ ./func the value is 0 the value... (5 Replies)
Discussion started by: boy18nj
5 Replies

7. Shell Programming and Scripting

[Bash]Function returning a boolean

Hello all, I would like to know if it is possible to return a the result of a boolean expression from a function like this function() { # some code return || } and what will be the return value ? Thank you for help. (6 Replies)
Discussion started by: dolphin06
6 Replies

8. Shell Programming and Scripting

bash search function

I want to have a function with a similar interface: search *.cpp asdf that will search recursively all directories for *.cpp file, containing line 'asdf' inside. I tried this: function search { find . -name "$1" | xargs grep -li $2; } But it doesn't work all the time. For example, if i run it... (3 Replies)
Discussion started by: doze
3 Replies

9. Shell Programming and Scripting

Need help in using power function in Bash

Hi, I would like to use a power function in Bash in an awk '{ } . e.g pow(2,3)=8 Any suggestion? I try to find online resources but most of them stated by using BC. Please advise. Thanks. (3 Replies)
Discussion started by: ahjiefreak
3 Replies

10. Shell Programming and Scripting

Need assistance with bash function

Hi all! I need a little help with an imbedded fuction I am trying to write. What I am trying to do is go to a series of hosts and get the contents of an XML file, storing some of the data, along with the name of the host it was gathered from. My intent is to store this in an array for later... (1 Reply)
Discussion started by: _jade_
1 Replies
Login or Register to Ask a Question