c856
![]() |
|
|
|
|
|||||||
| Userland Programming & Scripting C, Shell, Perl, Sed & Awk |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
||||
|
||||
|
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
|
|
#2
|
||||
|
||||
|
__________________
Senior UNIX Engineer at Unix Support Nederland Experience is something you don't get until just after you need it. |
|
#3
|
||||
|
||||
|
Quote:
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. |
|
#4
|
|||
|
|||
|
[ 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.
|
|
#5
|
||||
|
||||
|
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) |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |