我怎样才能让这个功能工作?
Esc在接受用户输入的同时按下将退出脚本
read -r -p "Enter the filenames: " -a arr
if press Esc; then
read $round
mkdir $round
fi
for filenames in "${arr[@]}"; do
if [[ -e "${filenames}" ]]; then
echo "${filenames} file exists (no override)"
else
cp -n ~/Documents/library/normal.cpp "${filenames}"
fi
done
如何检测Esc此脚本中的密钥?
PS:看到很多资源
https://www.linuxquestions.org/questions/linux-newbie-8/bash-esc-key-in-a-case-statement-759927/
他们使用另一个变量,例如$key
或read -n1 $key
仅一个字符输入
但是如果我有一个字符串或一个数组,我该怎么办?
最好的解决方案是从文件中读取文件路径或将它们作为参数传递给脚本,就像@terdon 说的那样
read
退出Escape 按键的最佳方式似乎是: https ://superuser.com/questions/1267984/how-to-exit-read-bash-builtin-by-pressing-the-esc-key/1447324# 1447324另一种较差的方式(它无法区分 Esc 和箭头键按下):
以下是我如何调整我的脚本。希望能帮助到你。
这应该在bash中工作: