logo Debian Debian Debian-France Debian-Facile Debian-fr.org Forum-Debian.fr Debian ? Communautés logo inclusivité

Debian-facile

Bienvenue sur Debian-Facile, site d'aide pour les nouveaux utilisateurs de Debian.

Vous n'êtes pas identifié(e).

#1 04-01-2017 18:56:29

Patrick Debian
Membre
Distrib. : Debian Buster main_contrib_non-free_backpor
(G)UI : Gnome
Inscription : 14-12-2016

erreur de syntaxe : fin de fichier prématurée ??? [résolu]

Bonsoir,
Dés que j'allume mon terminal, ceci s'affiche en première ligne, juste avant le prompt :

bash: /etc/bash.bashrc: ligne 56: erreur de syntaxe : fin de fichier prématurée



Je fais :

bash: /etc/bash.bashrc: ligne 56: erreur de syntaxe : fin de fichier prématurée



et je reçoit ça :

:/# cat -n /etc/bash.bashrc
     1  # System-wide .bashrc file for interactive bash(1) shells.
     2  
     3  # To enable the settings / commands in this file for login shells as well,
     4  # this file has to be sourced in /etc/profile.
     5  
     6  # If not running interactively, don't do anything
     7  [ -z "$PS1" ] && return
     8  
     9  # check the window size after each command and, if necessary,
    10  # update the values of LINES and COLUMNS.
    11  shopt -s checkwinsize
    12  
    13  # set variable identifying the chroot you work in (used in the prompt below)
    14  if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    15      debian_chroot=$(cat /etc/debian_chroot)
    16  fi
    17  
    18  # set a fancy prompt (non-color, overwrite the one in /etc/profile)
    19  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    20  
    21  # Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
    22  # If this is an xterm set the title to user@host:dir
    23  #case "$TERM" in
    24  #xterm*|rxvt*)
    25  #    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
    26  #    ;;
    27  #*)
    28  #    ;;
    29  #esac
    30  
    31  # enable bash completion in interactive shells
    32  if ! shopt -oq posix; then
    33    if [ -f /usr/share/bash-completion/bash_completion ]; then
    34      . /usr/share/bash-completion/bash_completion
    35    elif [ -f /etc/bash_completion ]; then
    36      . /etc/bash_completion
    37    fi
    38  fi
    39  
    40   if the command-not-found package is installed, use it
    41  if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
    42    function command_not_found_handle {
    43            # check because c-n-f could've been removed in the meantime
    44                  if [ -x /usr/lib/command-not-found ]; then
    45         /usr/lib/command-not-found -- "$1"
    46                     return $?
    47                  elif [ -x /usr/share/command-not-found/command-not-found ]; then
    48         /usr/share/command-not-found/command-not-found -- "$1"
    49                     return $?
    50      else
    51         printf "%s: command not found\n" "$1" >&2
    52         return 127:/# cat -n /etc/bash.bashrc
     1  # System-wide .bashrc file for interactive bash(1) shells.
     2  
     3  # To enable the settings / commands in this file for login shells as well,
     4  # this file has to be sourced in /etc/profile.
     5  
     6  # If not running interactively, don't do anything
     7  [ -z "$PS1" ] && return
     8  
     9  # check the window size after each command and, if necessary,
    10  # update the values of LINES and COLUMNS.
    11  shopt -s checkwinsize
    12  
    13  # set variable identifying the chroot you work in (used in the prompt below)
    14  if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    15      debian_chroot=$(cat /etc/debian_chroot)
    16  fi
    17  
    18  # set a fancy prompt (non-color, overwrite the one in /etc/profile)
    19  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    20  
    21  # Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
    22  # If this is an xterm set the title to user@host:dir
    23  #case "$TERM" in
    24  #xterm*|rxvt*)
    25  #    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
    26  #    ;;
    27  #*)
    28  #    ;;
    29  #esac
    30  
    31  # enable bash completion in interactive shells
    32  if ! shopt -oq posix; then
    33    if [ -f /usr/share/bash-completion/bash_completion ]; then
    34      . /usr/share/bash-completion/bash_completion
    35    elif [ -f /etc/bash_completion ]; then
    36      . /etc/bash_completion
    37    fi
    38  fi
    39  
    40   if the command-not-found package is installed, use it
    41  if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
    42    function command_not_found_handle {
    43            # check because c-n-f could've been removed in the meantime
    44                  if [ -x /usr/lib/command-not-found ]; then
    45         /usr/lib/command-not-found -- "$1"
    46                     return $?
    47                  elif [ -x /usr/share/command-not-found/command-not-found ]; then
    48         /usr/share/command-not-found/command-not-found -- "$1"
    49                     return $?
    50      else
    51         printf "%s: command not found\n" "$1" >&2
    52         return 127
    53      fi
    54    }
    55  fi

    53      fi
    54    }
    55  fi
 




pas de ligne 56.

J'ai cherché sur le net et j'ai trouvé le même problème, mais avec des scripts différents :
https://openclassrooms.com/forum/sujet/ … prematuree

https://www.debian-fr.org/t/probleme-bash/28044

Étant ignorant dans ce langage, je ne sais comment y remédier. Je vous remercie de m'aider.

Dernière modification par Patrick Debian (04-01-2017 20:25:14)

Hors ligne

#2 04-01-2017 18:59:37

enicar
Membre
Lieu : pas ici
Distrib. : sid
Noyau : Linux 6.5.3
(G)UI : openbox
Inscription : 26-08-2010

Re : erreur de syntaxe : fin de fichier prématurée ??? [résolu]

Essaye de supprimer les lignes 53, 54 et 55, je n'ai que survolé donc peut être que ça ne sera
pas ça, mais ça me semble plausible.

Hors ligne

#3 04-01-2017 19:07:44

chalu
Modératrice
Lieu : Anjou
Distrib. : openSUSE Tumbleweed
Noyau : Linux 5.12
(G)UI : KDE 5.21.4
Inscription : 11-03-2016

Re : erreur de syntaxe : fin de fichier prématurée ??? [résolu]

Bonsoir smile
Pour préciser ce que dit enicar, le problème vient sans doute des 3 dernières lignes qui sont en doublon des trois précédentes

  50      else
    51         printf "%s: command not found\n" "$1" >&2
    52         return 127
    53      fi
    54    }
    55  fi

    53      fi
    54    }
    55  fi


Ton fichier devrait finir simplement par

  50      else
    51         printf "%s: command not found\n" "$1" >&2
    52         return 127
    53      fi
    54    }
    55  fi
 


Il me semble qu'il y a d'autres soucis dans ton fichier car la numérotation va de 1 à 52 (au lieu de finir à 55) puis elle repart de 1 à 55 et enfin on a le reste de 53 à 54
ça donne l'impression qu'il y a eu un copier-coller des lignes de 1 à 55 inséré entre les lignes 52 et 53
Tu sais comment tu l'as modifié ? C'est un fichier système donc modifiable en étant en root. Il faut être vigilant avec les commandes et manipulations quand on est en root wink

Hors ligne

#4 04-01-2017 19:31:05

Patrick Debian
Membre
Distrib. : Debian Buster main_contrib_non-free_backpor
(G)UI : Gnome
Inscription : 14-12-2016

Re : erreur de syntaxe : fin de fichier prématurée ??? [résolu]

Désolé, j'ai essayé de faire bien avec la mise en couleurs, et je me suis planté.

Donc, je fais

 cat -n /etc/bash.bashrc




   et j'ai cela:

  1 # System-wide .bashrc file for interactive bash(1) shells.
     2 
     3  # To enable the settings / commands in this file for login shells as well,
     4  # this file has to be sourced in /etc/profile.
     5 
     6  # If not running interactively, don't do anything
     7  [ -z "$PS1" ] && return
     8 
     9  # check the window size after each command and, if necessary,
    10  # update the values of LINES and COLUMNS.
    11  shopt -s checkwinsize
    12 
    13  # set variable identifying the chroot you work in (used in the prompt below)
    14  if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    15      debian_chroot=$(cat /etc/debian_chroot)
    16  fi
    17 
    18  # set a fancy prompt (non-color, overwrite the one in /etc/profile)
    19  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    20 
    21  # Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
    22  # If this is an xterm set the title to user@host:dir
    23  #case "$TERM" in
    24  #xterm*|rxvt*)
    25  #    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
    26  #    ;;
    27  #*)
    28  #    ;;
    29  #esac
    30 
    31  # enable bash completion in interactive shells
    32  if ! shopt -oq posix; then
    33    if [ -f /usr/share/bash-completion/bash_completion ]; then
    34      . /usr/share/bash-completion/bash_completion
    35    elif [ -f /etc/bash_completion ]; then
    36      . /etc/bash_completion
    37    fi
    38  fi
    39 
    40   if the command-not-found package is installed, use it
    41  if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
    42    function command_not_found_handle {
    43            # check because c-n-f could've been removed in the meantime
    44                  if [ -x /usr/lib/command-not-found ]; then
    45         /usr/lib/command-not-found -- "$1"
    46                     return $?
    47                  elif [ -x /usr/share/command-not-found/command-not-found ]; then
    48         /usr/share/command-not-found/command-not-found -- "$1"
    49                     return $?
    50      else
    51         printf "%s: command not found\n" "$1" >&2
    52         return 127
    53      fi
    54    }
    55  fi
 

Hors ligne

#5 04-01-2017 19:40:34

enicar
Membre
Lieu : pas ici
Distrib. : sid
Noyau : Linux 6.5.3
(G)UI : openbox
Inscription : 26-08-2010

Re : erreur de syntaxe : fin de fichier prématurée ??? [résolu]

Ligne 40 il faut mette un # au tout début de la ligne

Au lieu de :


if the command-not-found package is installed, use it
 


mettre :


# if the command-not-found package is installed, use it
 



Car manifestement, c'est un commentaire.

Dernière modification par enicar (04-01-2017 19:44:38)

Hors ligne

#6 04-01-2017 19:43:46

chalu
Modératrice
Lieu : Anjou
Distrib. : openSUSE Tumbleweed
Noyau : Linux 5.12
(G)UI : KDE 5.21.4
Inscription : 11-03-2016

Re : erreur de syntaxe : fin de fichier prématurée ??? [résolu]

Si tu n'as pas fait d'erreur dans le copier-coller
il manque un # devant la ligne 40
ce qui fait un if ouvert mais pas fermé
Il faudrait avoir :


    38    fi
    39 
    40    # if the command-not-found package is installed, use it
    41    if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
    42       function command_not_found_handle {
 


Seule la ligne 40 est à modifier en ajoutant # au début pour commenter

Edit : enicar a été plus rapide wink

Hors ligne

#7 04-01-2017 19:47:05

smolski
quasi...modo
Lieu : AIN
Distrib. : backports (buster) 10
Noyau : Linux 4.19.0-8-amd64
(G)UI : gnome
Inscription : 21-10-2008

Re : erreur de syntaxe : fin de fichier prématurée ??? [résolu]

Commenter quoi t'est-ce que ?
Voir là :
https://debian-facile.org/doc:programmation:commenter

... character0071.gif

saque eud dun (patois chtimi : fonce dedans)

Hors ligne

#8 04-01-2017 20:23:58

Patrick Debian
Membre
Distrib. : Debian Buster main_contrib_non-free_backpor
(G)UI : Gnome
Inscription : 14-12-2016

Re : erreur de syntaxe : fin de fichier prématurée ??? [résolu]

Un grand merci à vous. Le problème est résolu!

Aaah, enicar a dégainé plus vite.

Je viens de lire deux fois le tuto sur # dans le langage de shell bash. Compris que # empêche le système de prendre en considération la ligne qui le suit, c'est donc très bien pour faire un commentaire.

Mais pourquoi fallait il mettre un dièse ? Cela reste un mystère pour moi.

Il se peut que ce la s'acquiert avec l'apprentissage des codes. J'en suit encore dans le « papillonage » de DF. Je patiente jusqu'à ce qu'un jour, je puisse me mettre à comprendre ce langage.

Merci.

Dernière modification par Patrick Debian (04-01-2017 20:24:44)

Hors ligne

#9 04-01-2017 20:34:11

enicar
Membre
Lieu : pas ici
Distrib. : sid
Noyau : Linux 6.5.3
(G)UI : openbox
Inscription : 26-08-2010

Re : erreur de syntaxe : fin de fichier prématurée ??? [résolu]

Pourquoi le #, je ne sais pas exactement, c'est un convention dans les shell unix qui a été repris
par quelques langages interprétés (ce qui veut dire que dans d'autres langages ça peut être différent).

Il se peut qu'il y ait une histoire derrière tout cela mais je ne la connais pas wink

Hors ligne

#10 04-01-2017 22:22:28

smolski
quasi...modo
Lieu : AIN
Distrib. : backports (buster) 10
Noyau : Linux 4.19.0-8-amd64
(G)UI : gnome
Inscription : 21-10-2008

Re : erreur de syntaxe : fin de fichier prématurée ??? [résolu]

Dans le tuto mis en lien post #7 lire la Remarque à la fin du tuto qui indique d'autres méthodes pour commenter selon le language employé.

saque eud dun (patois chtimi : fonce dedans)

Hors ligne

Pied de page des forums