歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Ubuntu下默認sh報錯的問題

最近在學shell編程,發現Ubuntu下的shell默認的是dash,非常難用。執行很多的腳本的時候會報些莫名其妙的錯誤。

  1. #!/bin/bash  
  2. # Program:  
  3. # This program shows the user's choice  
  4. # History:  
  5. # 2005/08/25 VBird First release  
  6. PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin  
  7. export PATH  
  8.   
  9. read -p "Please input (Y/N): " yn  
  10. [ "$yn" == "Y" -o "$yn" == "y" ] && echo "OK, continue" && exit 0  
  11. [ "$yn" == "N" -o "$yn" == "n" ] && echo "Oh, interrupt!" && exit 0  
  12. echo "I don't know what your choice is" && exit 0  

這個腳本是摘自鳥哥的私房菜第十三章p272的一個腳本,原來在其他發行版上是沒有問題的。但是在我電腦的ubuntu 12.04就會報錯。

[: 10: y: unexpected operator
I don't know what your choice is

百思不得其解,直到上網查資料提示我說檢測下執行腳食使用的是那個shell,才恍然大悟。

  1. www.linuxidc.com @linuxidc:~/bin$ ls -al /bin/sh  
  2. lrwxrwxrwx 1 root root 4 May 19 19:13 /bin/sh -> dash  

發現sh是執行dash的一個符號鏈接,而不是bash的。

於是找到了解決辦法:

  1. sudo rm /bin/sh  
  2. sudo ln -s /bin/bash /bin/sh  

刪除重建/bin/sh符號鏈接,使其指向默認的/bin/bash就可以解決了。

Copyright © Linux教程網 All Rights Reserved