相关疑难解决方法(0)

如何在bash中获取光标位置?

在bash脚本中,我想在变量中获取游标列.看起来使用ANSI转义码{ESC}[6n是获取它的唯一方法,例如以下方式:

# Query the cursor position
echo -en '\033[6n'

# Read it to a variable
read -d R CURCOL

# Extract the column from the variable
CURCOL="${CURCOL##*;}"

# We have the column in the variable
echo $CURCOL
Run Code Online (Sandbox Code Playgroud)

不幸的是,这会将字符打印到标准输出,我想静静地进行.此外,这不是很便携......

是否有一种纯粹的bash方式来实现这一目标?

bash cursor

25
推荐指数
4
解决办法
3万
查看次数

标签 统计

bash ×1

cursor ×1