Hello,
Here is my basic bash script "menu.sh" launching some commands, under KDE 3.5.7, Linux BT 2.6.21.5, Bash 3.1.17.
http://www.airfirst.ch/b2/menu.sh
And the output below.
STEP_A
First run: it fails on the 1st line.
STEP_B : I remove the first line: #!/bin/bash
Then it fails printing commands 03,05,06,08,11.
STEP_C : I replaced "$CN1" by its value "eth1" for commands 03,05,06,08,11.
Then it still fails printing commands 11.
1. How to fix the 1st line error? -bash: ./menu.sh: /bin/bash^M: bad interpreter: No such file or directory
Is tha because the file was created under MS Windows (then get it from VMware on a NT server)?
In VMware, if I create this file, I don't get the error on #!/bin/bash
Code:
#!/bin/bash
echo blabla
2. How to fix this echo printing bugs? It looks that only strings with something after a variable fail.
com03="dir $CN1 -all" : there is something after variable $CN1
com08="ifconfig $CN1 up hw ether $MAC" : there is something after variable $CN1
com12="echo --test -e $ESSID -a $BSSID $CN1" : OK because (maybe) $ESSID, $BSSID are not yet defined.
3. What's wrong in line 31?
4. What could be the crazy reason of this:
- Test to run menu1.sh, and works fine.
- Using Kate editor: select all content in menu1.sh, and paste it in empty menu.sh.
- Test to run menu.sh, and get error:
Code:
-bash: ./menu.sh: /bin/bash^M: bad interpreter: No such file or directory
Should I say "Damned Linux" or "Damned Bash" or what else ????????
Thanks and regards.
PS:
This menu1 works fine under Bash 3.1.17, Linux debbi 2.6.23 (no error):
http://www.airfirst.ch/b2/menu1.sh
http://www.airfirst.ch/b2/outpu_menu1.txt
----------------------------------------------------------------------------------------------------
STEP_A
Code:
bt Desktop # menu.sh
-bash: ./menu.sh: /bin/bash^M: bad interpreter: No such file or directory
STEP_B: I remove the 1st line: #!/bin/bash
Code:
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.
Code:
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
Code:
#!/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
#---------------------------------------------------------------------------------------------------