1. 程式人生 > >編寫shell時,遇到let: not found錯誤及解決辦法

編寫shell時,遇到let: not found錯誤及解決辦法

#!/bin/bash
i=1
sum=0
while [ $i -le 100 ]
do
  let sum=sum+$i
  let i++

done

在寫一個簡單的迴圈指令碼時,報錯 let: not found,在ubuntu預設是指向bin/dash直譯器的,dash是閹割版的bash,其功能遠沒有bash強大和豐富.並且dash不支援let和i++等功能.

 

解決辦法:

    sudo dpkg-reconfigure dash   選擇 "否", 表示用bash代替dash