bash shell退格键乱码

简介:
 我写了一个非常简单的脚本,用于上传某个文件到hadoop中hdfs的某个目录。在输入文件名称或目录名称时,有时候会输错,需要删除错误输入,但在敲退格键时时出现乱码^H,每按一下退格键就会出现一个^H。
    搜索网上资料,参考了如下网页,得到解决办法:http://hi.baidu.com/moonlight_bupt/blog/item/1b6a7acc5435c00700e928df.html,它提供了两个方法:
  一是,在敲退格键时,同时按住ctrl键;
  二是,修改.bash_profile文件:
     a)在bash下:$ stty erase ^?
     或者把 stty erase ^? 添加到.bash_profile中。
    b) 在csh下:$ stty erase ^H
     或者把 stty erase ^H 添加到.cshrc中。
     stty erase "^H"

    我两个方法都试验了一下,第一个方法没有问题,但在试验第二个方法时,出了问题,如下:
    我的默认shell是bash,脚本中调用的也是bash。我在.bash_profile中写入$ stty erase ^?,但根本没有效果!于是写入stty erase "^H",这才有效果
    后来仔细观察了一下,我在bash中敲退格键时出现^H,而这个字符应该是csh中出现的东西!不知道这个诡异的现象是怎么来的。
 
    附脚本:
 
  1. #!/bin/bash 
  2. #2011-06-07 by qinshan.li
  3. #
  4. echo -n "Type your path: " 
  5. read path 
  6. ~/hadoop-0.20.2-CDH3B4/bin/hadoop fs -mkdir ${path} 
  7. if [[ "$?" = "0" ]]; then 
  8. echo -e "$(date "+%T") : Create directory successfully! " 
  9. else 
  10. echo -e "$(date "+%T") : Create directory failed! " 
  11. fi 
  12.  
  13. echo -n "Type your file to upload: " 
  14. read file 
  15. ~/hadoop-0.20.2-CDH3B4/bin/hadoop fs -moveFromLocal ${file} ${path} 
  16. if [[ "$?" = "0" ]]; then 
  17. echo -e "$(date "+%T") : Uploaded successfully! " 
  18. else 
  19. echo -e "$(date "+%T") : Uploaded failed! " 
  20. fi 
本文转自 li_qinshan 51CTO博客,原文链接:
http://blog.51cto.com/share/583382

相关文章
|
4月前
|
移动开发 Shell Linux
百度搜索:蓝易云【Shell错误:/bin/bash^M: bad interpreter: No such file or directory】
将 `your_script.sh`替换为你的脚本文件名。运行此命令后,脚本文件的换行符将被转换为Linux格式,然后就可以在Linux系统上正常执行脚本了。
64 8
|
4月前
|
Linux Shell Windows
4:Bash shell命令-步入Linux的现代方法
4:Bash shell命令-步入Linux的现代方法
81 0
|
Ubuntu 安全 Linux
不用安装虚拟机,直接在Windows上面运行Linux Bash Shell,嗯!真香!!!
不用安装虚拟机,直接在Windows上面运行Linux Bash Shell,嗯!真香!!!
230 0
|
27天前
|
缓存 Shell Linux
在Linux中,bash shell 中的 hash 命令有什么作用?
在Linux中,bash shell 中的 hash 命令有什么作用?
|
30天前
|
Shell Linux
在Linux中,使用bash shell实现条件判断和循环结构的例子是什么样的?
在Linux中,使用bash shell实现条件判断和循环结构的例子是什么样的?
|
4月前
|
存储 Shell Linux
【攻防世界】unseping (反序列化与Linux bash shell)
【攻防世界】unseping (反序列化与Linux bash shell)
|
4月前
|
Shell
shell 命令(一)概述【别名、 bash重定向 、定义变量】
shell 命令(一)概述【别名、 bash重定向 、定义变量】
48 0
|
4月前
|
Shell
Shell(如Bash)命令行技巧
Shell(如Bash)命令行技巧
47 2
|
4月前
|
Shell
在Shell(如Bash)中,`while`循环
在Shell(如Bash)中,`while`循环
69 2
|
4月前
|
Unix Shell iOS开发
Shell错误:/bin/bash^M: bad interpreter: No such file or directory
Shell错误:/bin/bash^M: bad interpreter: No such file or directory
66 0