我想在一个有潜在危险的bash脚本的顶部快速提示“你确定吗?”以进行确认,最简单/最好的方法是什么?
当前回答
[[ -f ./${sname} ]] && read -p "File exists. Are you sure? " -n 1
[[ ! $REPLY =~ ^[Yy]$ ]] && exit 1
在函数中使用此选项查找现有文件并在覆盖之前提示。
其他回答
这是我在其他地方找到的,有更好的版本吗?
read -p "Are you sure you wish to continue?"
if [ "$REPLY" != "yes" ]; then
exit
fi
#!/bin/bash
echo Please, enter your name
read NAME
echo "Hi $NAME!"
if [ "x$NAME" = "xyes" ] ; then
# do something
fi
我是一个在bash中读取并回显结果的简短脚本。
尝试read shell内置:
read -p "Continue (y/n)?" CONT
if [ "$CONT" = "y" ]; then
echo "yaaa";
else
echo "booo";
fi
[[ -f ./${sname} ]] && read -p "File exists. Are you sure? " -n 1
[[ ! $REPLY =~ ^[Yy]$ ]] && exit 1
在函数中使用此选项查找现有文件并在覆盖之前提示。
echo are you sure?
read x
if [ "$x" = "yes" ]
then
# do the dangerous stuff
fi