Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoking program when a bash function has the same name

Tags:

bash

shell

I have the following function in my bash script:

make() {     cd Python-3.2     make } 

When make is called within this script, this function is invoked, which recurses. The call to make inside the function should actually invoke the external make utility. Other than renaming my make function, what's the cleanest way to achieve this?

like image 904
Matt Joiner Avatar asked Jun 16 '11 00:06

Matt Joiner


People also ask

What is $@ in bash?

bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc. Place variables in quotes if the values might have spaces in them.

Can a bash function call itself?

Functions in Bash also support recursion (the function can call itself). For example, F() { echo $1; F hello; sleep 1; } . A recursive function is a function that calls itself: recursive functions must have an exit condition, or they will spawn until the system exhausts a resource and crashes.

What does if Z do in bash?

if [ -z $SOMEVARIABLE ]; then echo "Do something here .... " In both cases, the -z flag is a parameter to the bash's "test" built-in (a built-in is a command that is built-into the shell, it is not an external command). The -z flag causes test to check whether a string is empty.


2 Answers

You can use the command built-in to suppress shell function lookups.

command: command [-pVv] command [arg ...]     Execute a simple command or display information about commands.      Runs COMMAND with ARGS suppressing  shell function lookup, or display     information about the specified COMMANDs.  Can be used to invoke commands     on disk when a function with the same name exists.      Options:       -p    use a default value for PATH that is guaranteed to find all of         the standard utilities       -v    print a description of COMMAND similar to the `type' builtin       -V    print a more verbose description of each COMMAND      Exit Status:     Returns exit status of COMMAND, or failure if COMMAND is not found. 
like image 77
Adam Bryzak Avatar answered Sep 20 '22 02:09

Adam Bryzak


Use the full path to the program. E.g. /usr/bin/make.

If you don't know the full path, you can use the which utility, like:

$(which make) 

That will find the full path and execute make.

like image 27
Gustavo Giráldez Avatar answered Sep 17 '22 02:09

Gustavo Giráldez