Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-05-2007, 11:43 PM   #1
Registered: Sep 2005
Posts: 201

Rep: Reputation: 30
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 [[ ]]
Old 08-06-2007, 02:22 AM   #2
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.5
Posts: 17,565

Rep: Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425
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).
Old 08-06-2007, 04:13 AM   #3
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
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.
Old 08-06-2007, 09:58 AM   #4
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,433

Rep: Reputation: 203Reputation: 203Reputation: 203
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

Last edited by bigearsbilly; 08-06-2007 at 10:00 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Scripting questions (2) rjcrews Programming 3 04-05-2006 01:14 PM
Bash Scripting paranoid times Programming 4 02-15-2006 11:48 AM
Bash scripting questions stryka Programming 3 11-25-2005 12:46 AM
bash scripting questions nix101 Linux - Newbie 2 09-04-2005 10:26 AM
Bash scripting questions irfanhab Programming 2 06-07-2004 01:13 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:25 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration