I am new to scripting.
My code is
#!/bin/bash
path=$1
if [ condition ]; then
.......
fi
How do i check if the argument is passed while calling the script?(What should i write as condition inside if statement)
I am new to scripting.
My code is
#!/bin/bash
path=$1
if [ condition ]; then
.......
fi
How do i check if the argument is passed while calling the script?(What should i write as condition inside if statement)
The syntax of a bash if
statement is:
if statement; ... then statement; ... else statement; ... fi
The statements following then
are executed if the last statement before then
succeeded; otherwise the statements following else
(if it is present; else
is optional.)
The number of arguments passed to a function is $#
.
You can do arithmetic comparisons with a conditional statement, whose syntax is (( arithmetic expression ))
. (The bash manual doesn't have a precise index tag for (( ))
; it's just underneath the provided link, which is for the select
statement.)
And finally found the answer with the help of all
if(($#==1));#check if number of arguments is 1 and return a boolean value
then
<code>
fi