Menu en Bash: Erreur sur echo (???)

Résolu/Fermé
budhax - 4 sept. 2008 à 20:49
 budhax - 6 sept. 2008 à 01:12
Bonjour,
MA CONFIG: BackTrack 3, KDE 3.5.7, Linux BT 2.6.21.5, Bash 3.1.17.
Sous cette config mon script "menu.sh" génère quelques erreurs.
http://www.airfirst.ch/b2/menu.sh
Voir l'output plus bas.
Comment les résoudre?

1. L'erreur sur la 1ère ligne: -bash: ./menu.sh: /bin/bash^M: bad interpreter: No such file or directory

2. Les erreur d'affichage des commandes: 03,05,06,08,11. Il s'emble que ça ne concerne que les chaine qui ont quelque chose après une variable !!!

3. L'erreur sur la ligne 31 (dans le bloc "case").

4. Question à 10000 points !!!!!
Que pourrait être la raison (à s'arracher les cheveux) de ceci:

- Teste du menu1.sh, OK sans erreur.
http://www.airfirst.ch/b2/menu1.sh
http://www.airfirst.ch/b2/outpu_menu1.txt
- Avec l'éditeur Kate, Copier tout le contenu de meni1.sh et coller dans menu.sh vide.
- Teste de menu.sh done l'erreur: -bash: ./menu.sh: /bin/bash^M: bad interpreter: No such file or directory

Qui puis-je maudire: Linux, Bash ou ... ?????

Merci


STEP_A
bt Desktop # menu.sh
-bash: ./menu.sh: /bin/bash^M: bad interpreter: No such file or directory



STEP_B: I remove the 1st line


bt Desktop # menu.sh
: command not found
: command not found
./menu.sh: line 13: menu: command not found

********************* TEST MENU
INIT
 01  ls
 02  dir eth1
 -alldir eth1
 04  iwlist eth1
 scaniwlist eth1
 mode monitor eth1
 07  echo start eth1
 up hw ether 50:41:32:23:14:05
MAIN
 09  Set ESSID: []
 10  Set BSSID: []
 eth1echo --write file
 12  echo --test -e  -a  eth1
Choix? 01
': not a valid identifier `com
'/menu.sh: line 31: syntax error near unexpected token `in
'/menu.sh: line 31: `  case "$com" in


STEP_C: I replaced "$CN1" by its value "eth1" for commands 03,05,06,08,11.


bt Desktop # menu.sh
: command not found
: command not found
./menu.sh: line 13: menu: command not found

********************* TEST MENU
INIT
 01  ls
 02  dir eth1
 03  dir eth1 -all
 04  iwlist eth1
 05  iwlist eth1 scan
 06  iwconfig eth1 mode monitor
 07  echo start eth1
 08  ifconfig eth1 up hw ether 50:41:32:23:14:05
MAIN
 09  Set ESSID: []
 10  Set BSSID: []
 eth1echo --write file
 12  echo --test -e  -a  eth1
Choix? 01
': not a valid identifier `com
'/menu.sh: line 31: syntax error near unexpected token `in
'/menu.sh: line 31: `  case "$com" in


menu.sh

#!/bin/bash

#------------------------------------------------------------------------------------ Initialisation
DFN=file
CN1=eth1
CN2=rausb0
RTAP0=rtap0
MESSID=IPW22
FIP_100=192.168.1.100
FIP_101=192.168.1.101
MAC=50:41:32:23:14:05
#----------------------------------------------------------------------------------------- Functions
menu {
  echo 
  echo "********************* TEST MENU"
  echo "INIT"
    com01="ls"                                              ; echo " 01  $com01"
    com02="dir $CN1"                                        ; echo " 02  $com02"
    com03="dir $CN1 -all"                                   ; echo " 03  $com03"
    com04="iwlist $CN1"                                     ; echo " 04  $com04"
    com05="iwlist $CN1 scan"                                ; echo " 05  $com05"
    com06="iwconfig $CN1 mode monitor"                      ; echo " 06  $com06"
    com07="echo start $CN1"                                 ; echo " 07  $com07"
    com08="ifconfig $CN1 up hw ether $MAC"                  ; echo " 08  $com08"
  echo "MAIN"
    com09="Set ESSID: [$ESSID]"                             ; echo " 09  $com09"
    com10="Set BSSID: [$BSSID]"                             ; echo " 10  $com10"
    com11="echo --write $DFN $CN1"                          ; echo " 11  $com11"
    com12="echo --test -e $ESSID -a $BSSID $CN1"            ; echo " 12  $com12"
  read -p "Choix? " com
  case "$com" in
    01) eval "$com01";;
    02) eval "$com02";;
    03) eval "$com03";;
    04) eval "$com04";;
    05) eval "$com05";;
    06) eval "$com06";;
    07) eval "$com07";;
    08) eval "$com08";;
    09) read -p "ESSID ? " ESSID;;
    10) read -p "BSSID ? " BSSID;;
    11) eval "$com11";;
    12) eval "$com12";;
    * ) echo "BYE ...."; exit;;
  esac
}
#---------------------------------------------------------------------------------------------- BODY
while true; do menu
done
exit
#---------------------------------------------------------------------------------------------------
A voir également:

2 réponses

jipicy Messages postés 40842 Date d'inscription jeudi 28 août 2003 Statut Modérateur Dernière intervention 10 août 2020 4 895
4 sept. 2008 à 20:58
Salut,

Convertis ton fichier au format UNIX avec "dos2unix" ou avec sed (voir dans la FAQ), et ça devrait aller mieux ;-))
1
Problème(s) fixé avec la commande dos2unix , merci jipicy.
dos2unix menu.sh


http://www.commentcamarche.net/faq/sujet 5978 sed conversion retours chariots dos crlf unix lf
0