shell stty : command not found

想测试下跑脚本暂停功能

抄了个网上脚本
https://www.cnblogs.com/zqb-a...

#!/bin/bash
#!/bin/stty
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

#test 

function get_char()
{
  SAVEDSTTY="stty -g"
  stty -echo
  stty cbreak
  dd if=/dev/tty bs=1 count=1 2> /dev/null
  stty -raw
  stty echo
  stty $SAVEDSTTY
}


echo "1"
echo "2"
get_char
echo "3"

运行结果是这样,搞不懂也百度不到答案。

1
2
test1.sh: line 10:   SAVEDSTTY=stty -g: command not found
test1.sh: line 11:   stty: command not found
test1.sh: line 12:   stty: command not found
test1.sh: line 14:   stty: command not found
test1.sh: line 15:   stty: command not found
test1.sh: line 16:   stty: command not found
3

谢谢大神了。

阅读 3.7k
1 个回答

是因为你的代码缩进行起始处有不可见的中文空格, 试试拷贝下面的代码试试:

#!/bin/bash


function get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}


echo "1"
echo "2"
get_char
echo "3"
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题