LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash scripting questions: (https://www.linuxquestions.org/questions/programming-9/bash-scripting-questions-574971/)

Geminias 08-05-2007 10:43 PM

Bash scripting questions:
 
1. Is the $# var not global? I can't seem to access it from within functions() in my script.

2. What is the difference between (( expression )) and [[ expression ]] my tutorial states that they are opposites however (( 5 > 9 )) evaluates to 1 (false) which is same with [[ ]]

chrism01 08-06-2007 01:22 AM

iirc, historically [[ ]] came first, for logical ie if/then tests.
(( )) came later in ksh and bash for 'built-in' arithmetic calcs, to avoid calling another (external) util eg expr.
However, (( )) will also return a true/false equiv under certain conditions (as per your example).
HTH

Hko 08-06-2007 03:13 AM

Quote:

Originally Posted by Geminias
1. Is the $# var not global? I can't seem to access it from within functions() in my script.

No, $# is not global. Inside a function $# contains the number of arguments passed to the function, not the numbers of arguments passed to the script.

bigearsbilly 08-06-2007 08:58 AM

you could do it by passing the scripts args again to the function

func "$@"

though of course they are now local to the function

so any changes made to the args will not propogate backwards to the caller

so a waste of time really


All times are GMT -5. The time now is 06:43 PM.