Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does if [[ $# -ge 1 ]] mean in shell scripting

Tags:

bash

shell

I was going over some files and found this:

if [[ $# -ge 1 ]]

What does that mean?

like image 563
mb47 Avatar asked Apr 20 '16 19:04

mb47


People also ask

What is if [[ ]] in Linux?

The [[ ... ]] part allows to test a condition using operators. Think of it as an if statement.

What does if mean in shell?

if is a command in Linux which is used to execute commands based on conditions. The 'if COMMANDS' list is executed. If its status is zero, then the 'then COMMANDS' list is executed.

What is if and fi?

fi statement is the fundamental control statement that allows Shell to make decisions and execute statements conditionally.

What is in if condition in bash?

The if statement is composed of the if keyword, the conditional phrase, and the then keyword. The fi keyword is used at the end of the statement. The COMMANDS gets executed if the CONDITION evaluates to True. Nothing happens if CONDITION returns False; the COMMANDS are ignored.


2 Answers

In shell script $# stores the number of arguments passed from the command line, like *argc in c programming.

So, By using the "if" statement we are verify the number of arguments are greater than or equal to one.

like image 186
Krishna Avatar answered Oct 12 '22 22:10

Krishna


if the number of passed parameters is greater than or equal to 1

like image 20
Jeff Puckett Avatar answered Oct 12 '22 23:10

Jeff Puckett