c856 BUG? -> sh: [ "$@" ] -> "eats" it's quotes! - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Development > Userland Programming & Scripting

Userland Programming & Scripting C, Shell, Perl, Sed & Awk

Reply
 
Thread Tools Display Modes
  #1  
Old November 10th, 2011, 17:35
Seeker's Avatar
Seeker Seeker is offline
Member
 
Join Date: May 2009
Location: Europe/Croatia/Zagreb
Posts: 834
Thanks: 13
Thanked 11 Times in 10 Posts
Default BUG? -> sh: [ "$@" ] -> "eats" it's quotes!

If [ "$@" ] is alone, err won't show up, but if you compare it ...

Code:
debug_fun ()
{
    local -
    set -x

    [ "$1" ] && echo '$1 - Empty!'
    [ "$*" ] && echo '$* - Empty!'
    [ "$@" ] && echo '$@ - Empty!'
}


debug_fun_compare ()
{
    local -
    set -x

    [ "$1" = ro ] && echo '$1 - Empty!'
    [ "$*" = ro ] && echo '$* - Empty!'
    [ "$@" = ro ] && echo '$@ - Empty!'
}


debug_fun

debug_fun_compare
Reply With Quote
  #2  
Old November 10th, 2011, 17:53
SirDice's Avatar
SirDice SirDice is offline
Moderator
 
Join Date: Nov 2008
Location: Rotterdam, Netherlands
Posts: 13,725
Thanks: 47
Thanked 2,023 Times in 1,862 Posts
Default

Not a bug.

http://www.grymoire.com/Unix/Sh.html#uh-42
__________________
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
Reply With Quote
  #3  
Old November 10th, 2011, 19:06
Seeker's Avatar
Seeker Seeker is offline
Member
 
Join Date: May 2009
Location: Europe/Croatia/Zagreb
Posts: 834
Thanks: 13
Thanked 11 Times in 10 Posts
Default

Quote:
Originally Posted by SirDice View Post
I know all this and it doesn't give an answer to this.
I'm talking about 0 args here in quotes (as $@ and $*, both behave same, when NOT surrounded with "").

Last edited by DutchDaemon; November 10th, 2011 at 21:40.
Reply With Quote
  #4  
Old November 13th, 2011, 18:23
jilles@ jilles@ is offline
FreeBSD Developer
 
Join Date: Sep 2010
Posts: 35
Thanks: 0
Thanked 10 Times in 9 Posts
Default

[ is expanded like any other simple command. The three tests in your first function are not all expanded the same but all are valid tests returning false. The third test in your second function causes a test(1) syntax error because "$@" expands to nothing at all if there are no positional parameters.
Reply With Quote
  #5  
Old November 13th, 2011, 18:52
Seeker's Avatar
Seeker Seeker is offline
Member
 
Join Date: May 2009
Location: Europe/Croatia/Zagreb
Posts: 834
Thanks: 13
Thanked 11 Times in 10 Posts
Default

That is exactly, why do I use double quotes around vars, to prevent syntax errors, in case when var isn't set/is undefined.
Problem is, "$@" acts like it was written as $@. It's double quotes disappear (Exposed via set -x in both functions)
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Solved] IFS goes "right through" double quotes in "${#str}" Seeker Userland Programming & Scripting 8 May 6th, 2011 13:54
/libexec/ld-elf.so.1: Shared object "libintl.so.8" not found, required by "pg_config" LocalEtc Installation and Maintenance of FreeBSD Ports or Packages 7 February 9th, 2011 18:30
[Solved] Shared object "libX11.so.6" not found, required by "soffice.bin" alie Installation and Maintenance of FreeBSD Ports or Packages 3 January 21st, 2011 03:31
[Solved] 7-2 hald_enable="YES" dbus_enable="YES" samba_enable="YES" not found ter2007 Installation and Maintenance of FreeBSD Ports or Packages 2 December 1st, 2009 15:58
Can not make " libnice" , error "-Wno-missing-field-initializers" admail2 Installation and Maintenance of FreeBSD Ports or Packages 10 June 26th, 2009 01:29


All times are GMT +1. The time now is 23:36.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0