LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell script problem (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-problem-460215/)

bondoq 07-02-2006 04:50 AM

shell script problem
 
i can't understand the if condition
this is an example but i can't understand what is th $1

$ cat > ispostive
#!/bin/sh
#
# Script to see whether argument is positive
#
if test $1 -gt 0
then
echo "$1 number is positive"
fi

plesae help me

thank you

SlackDaemon 07-02-2006 04:58 AM

The $1 variable refers to the first parameter passed to the script. The if statment just checks if the parameter given is greater than (-gt) 0.

BTW you may want to keep these sorts of questions in the 'newbie' or 'general' section. It is not relevant to networking.

bondoq 07-02-2006 05:36 AM

thank you for your help

but stil i dont know where is the first parameter

bondoq 07-02-2006 05:41 AM

thank you

i get it

but i have another question

what the diffrent between test statement and [ expr ] statement


thank you very much

scowles 07-02-2006 06:31 AM

The answer to all your questions can be found in the bash man pages.

Type: man bash

...at the first pause (bottom of screen -or- : ), type
/expr

from then on keep typing n (for next occurance)

Make sure you checkout the chapters labeled:
Positional Parameters
ARITHMETIC EVALUATION
CONDITIONAL EXPRESSIONS


All times are GMT -5. The time now is 07:14 PM.