- 在 bash 中要如何宣告並指定變數?
顯示答案
VARIABLE_NAME=value(等號兩側不可有空格)
- 在 bash 中,參照變數值的語法是什麼?
顯示答案
$VARIABLE_NAME 或 ${VARIABLE_NAME}
- 哪個指令可以匯出變數,讓子行程也能使用?
顯示答案
export VARIABLE_NAME
- 要如何把指令的執行結果指定給變數?
顯示答案
VARIABLE=$(command) 或 VARIABLE=`command`
- bash 中單引號和雙引號有什麼差別?
顯示答案
雙引號允許變數展開和指令替換;單引號會把所有內容都當成字面文字
- read 指令在 bash 腳本中的作用是什麼?
顯示答案
讀取使用者的輸入,並存入變數
- bash 中 if 敘述的基本結構是什麼?
顯示答案
if [ condition ]; then commands; fi
- 在 if 敘述中要如何測試檔案是否存在?
顯示答案
if [ -f /path/to/file ]; then
- 在 if 敘述中要如何測試目錄是否存在?
顯示答案
if [ -d /path/to/directory ]; then
- 條件判斷中的 -z 選項是測試什麼?
顯示答案
測試字串是否為空(長度為零)
- 條件判斷中的 -n 選項是測試什麼?
顯示答案
測試字串是否不為空(長度不為零)
- 在 if 敘述中要如何比較兩個數字?
顯示答案
在中括號內使用 -eq、-ne、-lt、-le、-gt 或 -ge
- bash 中 if-else 敘述的語法是什麼?
顯示答案
if [ condition ]; then commands; else commands; fi
- bash 中 if-elif-else 敘述的語法是什麼?
顯示答案
if [ condition1 ]; then commands; elif [ condition2 ]; then commands; else commands; fi
- bash 中 for 迴圈的基本結構是什麼?
顯示答案
for variable in list; do commands; done