Night shift


$ cat shift.ksh
#!/usr/bin/env ksh
echo $1 $2 $3
shift 2
echo $1 $2 $3
echo $?

Ezzel az egyszeru kis script-tel fogjuk tesztelni a shift mukodeset kulonbozo -- magukat tobbe kevesbe POSIX-nak vallo -- shell-ekben.

Kezdjuk Kenneth Almquist klasszikus SVR4 Bourne-shell kompatibilis implementaciojaval:


$ ./shift.netbsd-ash A B C                                                                                         
A B C
C
0
$ ./shift.netbsd-ash A B                                                                                           
A B

0
$ ./shift.netbsd-ash A                                                                                             
A
shift: can't shift that many

Nezzunk a public domain ksh-t:


$ ./shift.ksh A                                                                                                    
A
./shift.ksh[3]: shift: nothing to shift

Ugyanazt kapjuk, csak a hibauzenet szovege mas.
mksh ugyanezt az eredmenyt produkalja, de az egyaltalan nem meglepo. :)


Akkor jojjon a ksh93:

$ ./shift.ksh93  A                                                                                                 
A
./shift.ksh93[3]: shift: 2: bad number

Detto.

Akkor most kovetkezzek a nap poenja:


$ ./shift.bash A                                                                                                   
A
A
0

OH HAI! A**ad.

Van meg egy csodabogar:


$ ./shift.zsh  A                                                                                                   
A
./shift.zsh:shift:3: shift count must be <= $#
A
0

Legalabb szol, hogy ezt nem kellene. ;P

Na akkor most melyik a jo eljaras es kinek a k***a a***t?

Konkluzio:

hi, im bash

Hozzászólások

Mielőtt másokat kritizálsz, keresd a hibát a saját script-edben. Az echo visszatérési értékét nézed, nem a shift-ét...

AIX 5.3 ksh88

 # ./shift.aix-ksh88 A B C
A B C
C
0
 # ./shift.aix-ksh88 A B
A B

0
 # ./shift.aix-ksh88 A
A
./shift.aix-ksh88[3]: shift: 0403-009 The specified number is not valid for this command.
 #

RTFM ....


shift [n]
              The  positional  parameters  from n+1 ... are renamed to $1 ....
              Parameters represented by the numbers  $#  down  to  $#-n+1  are
              unset.   n  must  be a non-negative number less than or equal to
              $#.  If n is 0, no parameters are changed.  If n is  not  given,
              it  is assumed to be 1.  If n is greater than $#, the positional
              parameters are not changed.  The return status is  greater  than
              zero if n is greater than $# or less than zero; otherwise 0.

- man bash

linux v2.6.22.14 + madwifi v0.9.3.3-mal itt
debian gnu/linux @ linux-2.6.22.15-pancs1