我正在嘗試在除錯模式下運行一個簡單的腳本。
#!/bin/bash
trap 'read -p "run: $BASH_COMMAND"' DEBUG
command 1
command 2
**Current output:**
run: command 1 <press enter and the command executes>
run: command 2 <press enter and the command executes>
但我想在每次執行之前回圈詢問是/否
預期輸出:
run: command 1 yes/no? <input 'yes' enter and the command executes>
run: command 2 yes/no? <input 'yes' enter and the command executes>
我試過了
trap [['read -p "run: $BASH_COMMAND" && "continue [y/n]" ' ; echo $REPLY)" == [Yy]* ]] && echo Continuing || echo Stopping DEBUG
但我無法弄清楚。
基本上,我試圖在陷阱/除錯命令中執行兩次讀取操作,而在第二次讀取時,我想在執行之前執行邏輯操作。
有人能指出我正確的方向嗎?可能是行程替換
uj5u.com熱心網友回復:
也許像這樣
#! /bin/bash
confirm() {
read -rp "run: $BASH_COMMAND, continue [y/n]: "
if [[ "$REPLY" == [Yy]* ]]; then
echo Continuing
else
echo Stopping DEBUG
exit
fi
}
trap confirm DEBUG
command 1
command 2
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/524465.html
標籤:重击壳调试
