您可以在脚本中添加以下内容。当你的进程在后台时,它会给你终端 5 秒。
timelimit=5; ## The time limit in seconds
NEW_PROMPT_COMMAND="; if [[ \\\$SECONDS -gt $timelimit ]]; then echo \\\"---Timelimit hit, shutting down shell---\\\"; flush_keyboard_buffer; exit; fi";
touch ~/.bashrc_timelimit;
cp ~/.bashrc ~/.bashrc_timelimit;
(cat ~/.bashrc; echo -e "\nPROMPT_COMMAND+=\"$NEW_PROMPT_COMMAND\"") > ~/.bashrc_timelimit;
bash --rcfile ~/.bashrc_timelimit;
试试这个运行脚本来理解击球手 -
function pause(){
read -n 1 -p "$*"
}
clear
until [ "selection" = "0" ] ; do
echo " "
echo -e '\t\t\t' "Unix Helper Utility"
echo -e '\t\t\t' "==================="
echo " "
echo "[1] List File names in current directory"
echo "[2] Show Time and Date"
echo "[3] Process ID"
echo "[4] Send this menu to Background"
echo "[0] Exit"
echo " "
echo "Please pick an option listed above: "
read selection
echo " "
case $selection in
1 ) clear
echo " Current Directory list:"
ls
pause
clear ;;
2 ) clear
date
pause
clear ;;
3 ) clear
echo "option 3"
pause
clear ;;
4 ) clear
timelimit=5; ## The time limit in seconds
NEW_PROMPT_COMMAND="; if [[ \\\$SECONDS -gt $timelimit ]]; then echo \\\"---Timelimit hit, shutting down shell---\\\"; flush_keyboard_buffer; exit; fi";
touch ~/.bashrc_timelimit;
cp ~/.bashrc ~/.bashrc_timelimit;
(cat ~/.bashrc; echo -e "\nPROMPT_COMMAND+=\"$NEW_PROMPT_COMMAND\"") > ~/.bashrc_timelimit;
bash --rcfile ~/.bashrc_timelimit;
clear ;;
0 ) clear
exit
esac
done