FlashKeepers

Linux · CompTIA Linux+ · Professional Certifications

Linux Shell 腳本入門

bash shell 腳本的基本概念,包含變數、迴圈與條件判斷。

About this set

40 basic cards for CompTIA Linux+ Linux. It opens with "在 bash 中要如何宣告並指定變數?" and "在 bash 中,參照變數值的語法是什麼?".

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

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

25 more cards in the app

Study this set free