LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-02-2007, 02:34 PM   #1
onedingo
Member
 
Registered: Jan 2006
Location: Pittsburgh, PA, US
Distribution: Arch
Posts: 69

Rep: Reputation: 20
What is "/bin/[" ?


I am thinking that an install script was messed up and renamed something on move. Does anyone else have this file? I'm using Slack 11.0.

Here's the details:

Code:
owner@amd1200:~$ ls -l /bin/[
-rwxr-xr-x 1 root root 24376 2006-06-24 21:59 /bin/[*
owner@amd1200:~$ md5sum /bin/[
fa9b8269a2517d1e15ce053b0af2c6c4  /bin/[
owner@amd1200:~$ sha1sum /bin/[
9d1b9caba0f1cdf8a34c7abb4cb3f12a7cb6029e  /bin/[
owner@amd1200:~$ file /bin/[
/bin/[: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), stripped
owner@amd1200:~$ readelf -a /bin/[
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Intel 80386
  Version:                           0x1
  Entry point address:               0x8048c30
  Start of program headers:          52 (bytes into file)
  Start of section headers:          23296 (bytes into file)
  Flags:                             0x0
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         8
  Size of section headers:           40 (bytes)
  Number of section headers:         27
  Section header string table index: 26

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .interp           PROGBITS        08048134 000134 000013 00   A  0   0  1
  [ 2] .note.ABI-tag     NOTE            08048148 000148 000020 00   A  0   0  4
  [ 3] .hash             HASH            08048168 000168 000154 04   A  4   0  4
  [ 4] .dynsym           DYNSYM          080482bc 0002bc 0002e0 10   A  5   1  4
  [ 5] .dynstr           STRTAB          0804859c 00059c 0001f0 00   A  0   0  1
  [ 6] .gnu.version      VERSYM          0804878c 00078c 00005c 02   A  4   0  2
  [ 7] .gnu.version_r    VERNEED         080487e8 0007e8 000060 00   A  5   1  4
  [ 8] .rel.dyn          REL             08048848 000848 000028 08   A  4   0  4
  [ 9] .rel.plt          REL             08048870 000870 000130 08   A  4  11  4
  [10] .init             PROGBITS        080489a0 0009a0 000017 00  AX  0   0 16
  [11] .plt              PROGBITS        080489b8 0009b8 000270 04  AX  0   0  4
  [12] .text             PROGBITS        08048c30 000c30 0034b0 00  AX  0   0 16
  [13] .fini             PROGBITS        0804c0e0 0040e0 00001b 00  AX  0   0 16
  [14] .rodata           PROGBITS        0804c100 004100 00158f 00   A  0   0 32
  [15] .eh_frame_hdr     PROGBITS        0804d690 005690 00001c 00   A  0   0  4
  [16] .eh_frame         PROGBITS        0804d6ac 0056ac 00005c 00   A  0   0  4
  [17] .ctors            PROGBITS        0804e708 005708 000008 00  WA  0   0  4
  [18] .dtors            PROGBITS        0804e710 005710 000008 00  WA  0   0  4
  [19] .jcr              PROGBITS        0804e718 005718 000004 00  WA  0   0  4
  [20] .dynamic          DYNAMIC         0804e71c 00571c 0000c8 08  WA  5   0  4
  [21] .got              PROGBITS        0804e7e4 0057e4 000008 04  WA  0   0  4
  [22] .got.plt          PROGBITS        0804e7ec 0057ec 0000a4 04  WA  0   0  4
  [23] .data             PROGBITS        0804e890 005890 000020 00  WA  0   0  4
  [24] .bss              NOBITS          0804e8c0 0058b0 000168 00  WA  0   0 32
  [25] .comment          PROGBITS        00000000 0058b0 00017a 00      0   0  1
  [26] .shstrtab         STRTAB          00000000 005a2a 0000d5 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  PHDR           0x000034 0x08048034 0x08048034 0x00100 0x00100 R E 0x4
  INTERP         0x000134 0x08048134 0x08048134 0x00013 0x00013 R   0x1
      [Requesting program interpreter: /lib/ld-linux.so.2]
  LOAD           0x000000 0x08048000 0x08048000 0x05708 0x05708 R E 0x1000
  LOAD           0x005708 0x0804e708 0x0804e708 0x001a8 0x00320 RW  0x1000
  DYNAMIC        0x00571c 0x0804e71c 0x0804e71c 0x000c8 0x000c8 RW  0x4
  NOTE           0x000148 0x08048148 0x08048148 0x00020 0x00020 R   0x4
  GNU_EH_FRAME   0x005690 0x0804d690 0x0804d690 0x0001c 0x0001c R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4

 Section to Segment mapping:
  Segment Sections...
   00
   01     .interp
   02     .interp .note.ABI-tag .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame
   03     .ctors .dtors .jcr .dynamic .got .got.plt .data .bss
   04     .dynamic
   05     .note.ABI-tag
   06     .eh_frame_hdr
   07

Dynamic section at offset 0x571c contains 20 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
 0x0000000c (INIT)                       0x80489a0
 0x0000000d (FINI)                       0x804c0e0
 0x00000004 (HASH)                       0x8048168
 0x00000005 (STRTAB)                     0x804859c
 0x00000006 (SYMTAB)                     0x80482bc
 0x0000000a (STRSZ)                      496 (bytes)
 0x0000000b (SYMENT)                     16 (bytes)
 0x00000015 (DEBUG)                      0x0
 0x00000003 (PLTGOT)                     0x804e7ec
 0x00000002 (PLTRELSZ)                   304 (bytes)
 0x00000014 (PLTREL)                     REL
 0x00000017 (JMPREL)                     0x8048870
 0x00000011 (REL)                        0x8048848
 0x00000012 (RELSZ)                      40 (bytes)
 0x00000013 (RELENT)                     8 (bytes)
 0x6ffffffe (VERNEED)                    0x80487e8
 0x6fffffff (VERNEEDNUM)                 1
 0x6ffffff0 (VERSYM)                     0x804878c
 0x00000000 (NULL)                       0x0

Relocation section '.rel.dyn' at offset 0x848 contains 5 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0804e7e8  00002d06 R_386_GLOB_DAT    00000000   __gmon_start__
0804e8c0  00000a05 R_386_COPY        0804e8c0   opterr
0804e8c4  00000b05 R_386_COPY        0804e8c4   stdout
0804e8c8  00000c05 R_386_COPY        0804e8c8   stderr
0804e8cc  00002b05 R_386_COPY        0804e8cc   optind

Relocation section '.rel.plt' at offset 0x870 contains 38 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0804e7f8  00000107 R_386_JUMP_SLOT   00000000   __fpending
0804e7fc  00000207 R_386_JUMP_SLOT   00000000   fputs_unlocked
0804e800  00000307 R_386_JUMP_SLOT   00000000   strcmp
0804e804  00000407 R_386_JUMP_SLOT   00000000   fprintf
0804e808  00000507 R_386_JUMP_SLOT   00000000   dcgettext
0804e80c  00000607 R_386_JUMP_SLOT   00000000   setlocale
0804e810  00000707 R_386_JUMP_SLOT   00000000   __cxa_atexit
0804e814  00000807 R_386_JUMP_SLOT   00000000   __errno_location
0804e818  00000907 R_386_JUMP_SLOT   00000000   malloc
0804e81c  00000d07 R_386_JUMP_SLOT   00000000   abort
0804e820  00000e07 R_386_JUMP_SLOT   00000000   vfprintf
0804e824  00000f07 R_386_JUMP_SLOT   00000000   bindtextdomain
0804e828  00001007 R_386_JUMP_SLOT   00000000   strlen
0804e82c  00001107 R_386_JUMP_SLOT   00000000   fflush_unlocked
0804e830  00001207 R_386_JUMP_SLOT   00000000   __strtol_internal
0804e834  00001307 R_386_JUMP_SLOT   00000000   mbrtowc
0804e838  00001407 R_386_JUMP_SLOT   00000000   __xstat64
0804e83c  00001507 R_386_JUMP_SLOT   00000000   __libc_start_main
0804e840  00001607 R_386_JUMP_SLOT   00000000   realloc
0804e844  00001707 R_386_JUMP_SLOT   00000000   textdomain
0804e848  00001807 R_386_JUMP_SLOT   00000000   printf
0804e84c  00001907 R_386_JUMP_SLOT   00000000   memcpy
0804e850  00001a07 R_386_JUMP_SLOT   00000000   fclose
0804e854  00001b07 R_386_JUMP_SLOT   00000000   getopt_long
0804e858  00001c07 R_386_JUMP_SLOT   00000000   __lxstat64
0804e85c  00001d07 R_386_JUMP_SLOT   00000000   __ctype_get_mb_cur_max
0804e860  00001e07 R_386_JUMP_SLOT   00000000   exit
0804e864  00001f07 R_386_JUMP_SLOT   00000000   getegid
0804e868  00002007 R_386_JUMP_SLOT   00000000   calloc
0804e86c  00002107 R_386_JUMP_SLOT   00000000   euidaccess
0804e870  00002207 R_386_JUMP_SLOT   00000000   iswprint
0804e874  00002307 R_386_JUMP_SLOT   00000000   free
0804e878  00002407 R_386_JUMP_SLOT   00000000   isatty
0804e87c  00002507 R_386_JUMP_SLOT   00000000   memset
0804e880  00002607 R_386_JUMP_SLOT   00000000   mbsinit
0804e884  00002807 R_386_JUMP_SLOT   00000000   error
0804e888  00002a07 R_386_JUMP_SLOT   00000000   __ctype_b_loc
0804e88c  00002c07 R_386_JUMP_SLOT   00000000   geteuid

There are no unwind sections in this file.

Symbol table '.dynsym' contains 46 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 00000000    44 FUNC    GLOBAL DEFAULT  UND __fpending@GLIBC_2.2 (2)
     2: 00000000   160 FUNC    GLOBAL DEFAULT  UND fputs_unlocked@GLIBC_2.1 (3)
     3: 00000000    67 FUNC    GLOBAL DEFAULT  UND strcmp@GLIBC_2.0 (4)
     4: 00000000    33 FUNC    GLOBAL DEFAULT  UND fprintf@GLIBC_2.0 (4)
     5: 00000000    67 FUNC    GLOBAL DEFAULT  UND dcgettext@GLIBC_2.0 (4)
     6: 00000000  1600 FUNC    GLOBAL DEFAULT  UND setlocale@GLIBC_2.0 (4)
     7: 00000000    60 FUNC    GLOBAL DEFAULT  UND __cxa_atexit@GLIBC_2.1.3 (5)
     8: 00000000    54 FUNC    GLOBAL DEFAULT  UND __errno_location@GLIBC_2.0 (4)
     9: 00000000   497 FUNC    GLOBAL DEFAULT  UND malloc@GLIBC_2.0 (4)
    10: 0804e8c0     4 OBJECT  GLOBAL DEFAULT   24 opterr@GLIBC_2.0 (4)
    11: 0804e8c4     4 OBJECT  GLOBAL DEFAULT   24 stdout@GLIBC_2.0 (4)
    12: 0804e8c8     4 OBJECT  GLOBAL DEFAULT   24 stderr@GLIBC_2.0 (4)
    13: 00000000   535 FUNC    GLOBAL DEFAULT  UND abort@GLIBC_2.0 (4)
    14: 00000000 16011 FUNC    GLOBAL DEFAULT  UND vfprintf@GLIBC_2.0 (4)
    15: 00000000    29 FUNC    GLOBAL DEFAULT  UND bindtextdomain@GLIBC_2.0 (4)
    16: 00000000   175 FUNC    GLOBAL DEFAULT  UND strlen@GLIBC_2.0 (4)
    17: 00000000    62 FUNC    GLOBAL DEFAULT  UND fflush_unlocked@GLIBC_2.0 (4)
    18: 00000000    93 FUNC    GLOBAL DEFAULT  UND __strtol_internal@GLIBC_2.0 (4)
    19: 00000000   650 FUNC    GLOBAL DEFAULT  UND mbrtowc@GLIBC_2.0 (4)
    20: 00000000    54 FUNC    GLOBAL DEFAULT  UND __xstat64@GLIBC_2.2 (2)
    21: 00000000   222 FUNC    GLOBAL DEFAULT  UND __libc_start_main@GLIBC_2.0 (4)
    22: 00000000   820 FUNC    GLOBAL DEFAULT  UND realloc@GLIBC_2.0 (4)
    23: 00000000   259 FUNC    GLOBAL DEFAULT  UND textdomain@GLIBC_2.0 (4)
    24: 00000000    54 FUNC    GLOBAL DEFAULT  UND printf@GLIBC_2.0 (4)
    25: 00000000    70 FUNC    GLOBAL DEFAULT  UND memcpy@GLIBC_2.0 (4)
    26: 00000000   471 FUNC    GLOBAL DEFAULT  UND fclose@GLIBC_2.1 (3)
    27: 00000000    69 FUNC    GLOBAL DEFAULT  UND getopt_long@GLIBC_2.0 (4)
    28: 00000000    54 FUNC    GLOBAL DEFAULT  UND __lxstat64@GLIBC_2.2 (2)
    29: 00000000    60 FUNC    GLOBAL DEFAULT  UND __ctype_get_mb_cur_max@GLIBC_2.0 (4)
    30: 00000000   217 FUNC    GLOBAL DEFAULT  UND exit@GLIBC_2.0 (4)
    31: 00000000    12 FUNC    GLOBAL DEFAULT  UND getegid@GLIBC_2.0 (4)
    32: 00000000   916 FUNC    GLOBAL DEFAULT  UND calloc@GLIBC_2.0 (4)
    33: 00000000   285 FUNC    GLOBAL DEFAULT  UND euidaccess@GLIBC_2.0 (4)
    34: 00000000   231 FUNC    GLOBAL DEFAULT  UND iswprint@GLIBC_2.0 (4)
    35: 00000000   227 FUNC    GLOBAL DEFAULT  UND free@GLIBC_2.0 (4)
    36: 00000000    50 FUNC    GLOBAL DEFAULT  UND isatty@GLIBC_2.0 (4)
    37: 00000000    93 FUNC    GLOBAL DEFAULT  UND memset@GLIBC_2.0 (4)
    38: 00000000    25 FUNC    GLOBAL DEFAULT  UND mbsinit@GLIBC_2.0 (4)
    39: 0804c104     4 OBJECT  GLOBAL DEFAULT   14 _IO_stdin_used
    40: 00000000   240 FUNC    GLOBAL DEFAULT  UND error@GLIBC_2.0 (4)
    41: 00000000     0 NOTYPE  WEAK   DEFAULT  UND _Jv_RegisterClasses
    42: 00000000   122 FUNC    GLOBAL DEFAULT  UND __ctype_b_loc@GLIBC_2.3 (6)
    43: 0804e8cc     4 OBJECT  GLOBAL DEFAULT   24 optind@GLIBC_2.0 (4)
    44: 00000000    12 FUNC    GLOBAL DEFAULT  UND geteuid@GLIBC_2.0 (4)
    45: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__

Histogram for bucket list length (total of 37 buckets):
 Length  Number     % of total  Coverage
      0  11         ( 29.7%)
      1  14         ( 37.8%)     31.1%
      2  7          ( 18.9%)     62.2%
      3  4          ( 10.8%)     88.9%
      4  0          (  0.0%)     88.9%
      5  1          (  2.7%)    100.0%

Version symbols section '.gnu.version' contains 46 entries:
 Addr: 000000000804878c  Offset: 0x00078c  Link: 4 (.dynsym)
  000:   0 (*local*)       2 (GLIBC_2.2)     3 (GLIBC_2.1)     4 (GLIBC_2.0)
  004:   4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)     5 (GLIBC_2.1.3)
  008:   4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)
  00c:   4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)
  010:   4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)
  014:   2 (GLIBC_2.2)     4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)
  018:   4 (GLIBC_2.0)     4 (GLIBC_2.0)     3 (GLIBC_2.1)     4 (GLIBC_2.0)
  01c:   2 (GLIBC_2.2)     4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)
  020:   4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)
  024:   4 (GLIBC_2.0)     4 (GLIBC_2.0)     4 (GLIBC_2.0)     1 (*global*)
  028:   4 (GLIBC_2.0)     0 (*local*)       6 (GLIBC_2.3)     4 (GLIBC_2.0)
  02c:   4 (GLIBC_2.0)     0 (*local*)

Version needs section '.gnu.version_r' contains 1 entries:
 Addr: 0x00000000080487e8  Offset: 0x0007e8  Link to section: 5 (.dynstr)
  000000: Version: 1  File: libc.so.6  Cnt: 5
  0x0010:   Name: GLIBC_2.3  Flags: none  Version: 6
  0x0020:   Name: GLIBC_2.1.3  Flags: none  Version: 5
  0x0030:   Name: GLIBC_2.0  Flags: none  Version: 4
  0x0040:   Name: GLIBC_2.1  Flags: none  Version: 3
  0x0050:   Name: GLIBC_2.2  Flags: none  Version: 2
 
Old 03-02-2007, 02:42 PM   #2
MQMan
Member
 
Registered: Jan 2004
Location: Los Angeles
Distribution: Slack64 14.1
Posts: 581

Rep: Reputation: 38
Don't know what it does, but it's part of the coreutils package.

Cheers.
 
Old 03-02-2007, 02:50 PM   #3
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
I think it is the same as the 'test' statement when writing bash scripts.

for example:
Code:
if test a = b
then
echo 1
fi

# is the same as

if [ a = b ]
then
echo 1
fi
or maybe not .. I don't really know

Last edited by H_TeXMeX_H; 03-02-2007 at 02:55 PM.
 
Old 03-02-2007, 02:57 PM   #4
onedingo
Member
 
Registered: Jan 2006
Location: Pittsburgh, PA, US
Distribution: Arch
Posts: 69

Original Poster
Rep: Reputation: 20
OK

I did a
$ /bin/[ --help
and it gave me some info.

Didn't want to run it until I had some idea of where it came from.

This is my new favorite obscure Linux command...

Thanks.

Last edited by onedingo; 03-02-2007 at 03:05 PM.
 
Old 03-02-2007, 03:42 PM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
great ... so I was right after all.
 
Old 03-02-2007, 03:49 PM   #6
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
Yeah you can do

[[ x==y ]]

for example without the 'if' in bash scripts.
 
Old 03-02-2007, 04:51 PM   #7
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
I think 'if test' is the most readable, and what I always use.
 
Old 03-03-2007, 01:45 AM   #8
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
On some systems [ is just a link to test. Note that using double brackets is the same as using 'if test' or 'if [ ]'.

I use the brackets often for short routines where the tests don't get too complex, because it lets me write on one line what usually takes 3. Instead of:

if [ $I = $YOU ] ; then
exec prog
fi

I write it like this:

[[ "$I" = "$YOU" ]] && exec prog

Another example with a single test condition and two outcomes:

! [[ $VAR ]] && echo "VAR=$VAR" || VAR="default value"
This example written with 'normal' syntax takes 5 lines.
For the rules about usage see the 'test' man-page
 
Old 03-03-2007, 11:40 AM   #9
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Like always there's a trade-off ... readability vs. length of script.

You can't tell me that '! [[ $VAR ]] && echo "VAR=$VAR" || VAR="default value"' is readable.
 
Old 03-03-2007, 02:16 PM   #10
xflow7
Member
 
Registered: May 2004
Distribution: Slackware
Posts: 215

Rep: Reputation: 45
Quote:
Originally Posted by gnashley
On some systems [ is just a link to test. Note that using double brackets is the same as using 'if test' or 'if [ ]'.

I use the brackets often for short routines where the tests don't get too complex, because it lets me write on one line what usually takes 3. Instead of:

if [ $I = $YOU ] ; then
exec prog
fi

I write it like this:

[[ "$I" = "$YOU" ]] && exec prog

Another example with a single test condition and two outcomes:

! [[ $VAR ]] && echo "VAR=$VAR" || VAR="default value"
This example written with 'normal' syntax takes 5 lines.
For the rules about usage see the 'test' man-page
Why do you need the double brackets in those constructs?

Wouldn't:

[ "$I" = "$YOU" ] && exec prog

be sufficient?
 
Old 03-04-2007, 05:04 AM   #11
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
In most cases using single brackets gives the same result, but not always. It depends if you are comparing two variables or using the stderr returned to check something.

Of course I don't think that the abbreviated form is very readable for many people. That's one of the reasond I don't use it much anymore, Plus, it is more difficult to get multiple elifs to work as you want. Sometimes when I have nested ifs several layers deep, I'll alternate using if/thens on one level, double brackets on the next and so on.

You have to use single brackets for 'or' constructs like this:
if [ "$VAR" = "$VAL" -o "$VAR" = "$OTHERVAL" ] ; then
and everything has to be quoted.

These are equivalent:

if test true ; then echo yes; else echo false ;fi

[ true ] && echo yes ||echo false

Or, if you will:
if test true
then
echo yes
else
echo false
fi


[ true ] &&\
echo yes \
||echo false
 
Old 03-04-2007, 07:26 AM   #12
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
Quote:
Originally Posted by H_TeXMeX_H
You can't tell me that '! [[ $VAR ]] && echo "VAR=$VAR" || VAR="default value"' is readable.
When you have used that form for a while it's just as easy to read as any other test. A well used example is this in .bash_profile:

[[ -f ~/.bashrc ]] && . ~/.bashrc
 
Old 03-04-2007, 09:33 AM   #13
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Not sure what the [ function is called, but it is definitely a part of the installation, a valid file or program.
To add to the things you can use it for, consider:

printf "\033[1;32m Hello world...\n"

The escaped ascii 033 followed by [ and then the 1;32m will set the console text color to light green. 32 is for green, the 1 is for brightness or boldness (light green as opposed to dark) and I guess the [ has *something* to do with it, though I'm not certain in this context if it is actually calling that function.
These color changes can for example be used to colorize boot rc.scripts.
The default console color gets applied with '\033[0m'

Last edited by GrapefruiTgirl; 03-04-2007 at 09:34 AM.
 
Old 03-04-2007, 10:57 AM   #14
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Somewhat off topic here, but I read a comment by in GrokLaw a few days ago that /bin was so named by Thompson or Ritchy because they were thinking of a "tool bin" to hold the system's tools.

That may be why you'll find non-binary executables in /bin directories.

Even further off topic: I read a comment in LinuxQuestions that suggested the /usr directory was names that because it was intended to hold "Unix System Resources" rather then "User" stuff, but I've never seen that confirmed.
 
Old 03-04-2007, 11:23 AM   #15
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
Hmm, I thought that "test" or [[ ]] is a function built into the shell (ie Bash) ???

As test is a shell function ... why would you need /bin/[
 
  


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
"/usr/bin/ls: reading directory .: Input/output error" DiZi Slackware 15 07-13-2008 10:03 AM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 04:51 AM
"accidently deleted every program in /usr/bin that begins with the letter m*" behmjoe Linux From Scratch 1 04-15-2005 08:42 AM
open ".cu " and ".bin " on linux j.vilon Linux - General 17 11-19-2004 12:45 PM
what is "S" instead of "X" in the file permission when i look at /usr/bin/chsh? Linux_interest Linux - Newbie 4 08-28-2004 09:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:29 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