Scripts kai CR-LF

Michael Iatrou iatrou at serverhive.com
Wed Oct 5 04:46:06 EEST 2005


When the date was Monday 03 October 2005 18:16, Antonios Christofides wrote:

> anthony at voltaire:/var/tmp$ cat >hello
> #!/bin/bash
> echo 'Hello, world!'
> anthony at voltaire:/var/tmp$ chmod 755 hello
> anthony at voltaire:/var/tmp$ ./hello
> Hello, world!
> anthony at voltaire:/var/tmp$ unix2dos hello
> anthony at voltaire:/var/tmp$ ./hello
>
> : bad interpreter: No such file or directory
>
> Το carriage return δεν είναι white space; Το man isspace λέει πως
> είναι, τουλάχιστον σε locales C και POSIX (και τα παραπάνω τα δοκίμασα
> σε POSIX).

Στο fs/binfmt_script.c, στo kernel source, μπορείς να δεις γιατί συμβαίνει 
αυτό:

     38     bprm->buf[BINPRM_BUF_SIZE - 1] = '\0';
     39     if ((cp = strchr(bprm->buf, '\n')) == NULL)
     40         cp = bprm->buf+BINPRM_BUF_SIZE-1;
     41     *cp = '\0';
     42     while (cp > bprm->buf) {
     43         cp--;
     44         if ((*cp == ' ') || (*cp == '\t'))
     45             *cp = '\0';
     46         else
     47             break;
     48     }
     49     for (cp = bprm->buf+2; (*cp == ' ') || (*cp == '\t'); cp++);
     50     if (*cp == '\0')
     51         return -ENOEXEC; /* No interpreter name found */
     52     i_name = cp;
     53     i_arg = NULL;
     54     for ( ; *cp && (*cp != ' ') && (*cp != '\t'); cp++)
     55         /* nothing */ ;
     56     while ((*cp == ' ') || (*cp == '\t'))
     57         *cp++ = '\0';
     58     if (*cp)
     59         i_arg = cp;
     60     strcpy (interp, i_name);

Συγκεκριμένα, στη γραμμή 44, όπου φαίνεται να λαμβάνει υπόψη ως white spaces 
μόνο το space και το tab.

Αν όμως χρησιμοποιήσεις το παρακάτω ξεδιάντροπα απλό patch, δεν θα υπάρχει 
κανένα πρόβλημα.

-- 
 Μιχάλης Ιατρού
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p
Type: text/x-diff
Size: 363 bytes
Desc: not available
URL: <http://lists.hellug.gr/pipermail/linux-greek-users/attachments/20051005/5eb63362/attachment.diff>


More information about the Linux-greek-users mailing list