LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 08-05-2007, 10:43 PM   #1
Geminias
Member
 
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, 01:22 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

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

Rep: Reputation: 111Reputation: 111
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.
 
Old 08-06-2007, 08:58 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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 09:00 AM.
 
  


Reply



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 12:14 PM
Bash Scripting paranoid times Programming 4 02-15-2006 10:48 AM
Bash scripting questions stryka Programming 3 11-24-2005 11:46 PM
bash scripting questions nix101 Linux - Newbie 2 09-04-2005 09:26 AM
Bash scripting questions irfanhab Programming 2 06-07-2004 12:13 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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