Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty function in BASH

I'm using FPM tool to create .deb package. This tool create before/after remove package from supported files.

Unfortunatly the bash script generated by FPM contains such function

dummy() {
}

And this script exit with an error:

Syntax error: "}" unexpected

Does BASH doesn't allow empty functions? Which version of bash/linux have this limitation?

like image 400
user3550394 Avatar asked Jun 23 '15 09:06

user3550394


People also ask

What is empty bash?

To find out if a bash variable is empty: Return true if a bash variable is unset or set to the empty string: if [ -z "$var" ]; Another option: [ -z "$var" ] && echo "Empty" Determine if a bash variable is empty: [[ !

What is $0 in bash script?

The $0 special variable can be used in the terminal to print the name of your current shell simply by executing the following statement: $ echo $0.

What are functions in bash?

A bash function is a method used in shell scripts to group reusable code blocks. This feature is available for most programming languages, known under different names such as procedures, methods, or subroutines.

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.


3 Answers

You could use : that is equivalent to true and is mostly used as do nothing operator...

dummy(){
     : 
  }
like image 198
orestiss Avatar answered Oct 13 '22 20:10

orestiss


A one liner

dummy(){ :; }


: is the null command

; is needed in the one line format

like image 34
JobJob Avatar answered Oct 13 '22 20:10

JobJob


An empty bash function may be illegal. function contains only comments will be considered to be empty too.

a ":" (null command) can be placed in function if you want to "DO NOTHING"

see: http://tldp.org/LDP/abs/html/functions.html

like image 8
YangwuWang Avatar answered Oct 13 '22 20:10

YangwuWang