Skip to Content
bash shell脚本编程经典实例 (第2版)
book

bash shell脚本编程经典实例 (第2版)

by Carl Albing, JP Vossen
January 2021
Intermediate to advanced
581 pages
15h 7m
Chinese
Posts & Telecom Press
Content preview from bash shell脚本编程经典实例 (第2版)
472
19
端设置。你可以先多按几次
Enter
键,以确保开始输入
stty
命令时,命令行上没有残留别
的内容。
如果经常要这么做,不妨考虑创建一个便于盲打的别名(参见
10.7
)。
19.9.3
 讨论
如果在提示输入密码时中止,有些老版本的
ssh
有可能会关闭终端的回显功能(显示从键
盘上输入的字符,不是指
shell
echo
命令),导致用户看不到任何输入。根据使用的终端
仿真器显示二进制文件也可能会意外地改变终端设置。不管是哪种情况,
stty sane
会尝
试将所有的终端设置还原成默认值,其中包括恢复回显功能,这样一来,键盘输入的内容
就能出现在终端窗口中了。这也许还能消除其他终端设置中出现的奇怪现象。
你使用的终端应用可能也具有某种重置功能,不妨研究一下菜单选项和文档。你也可以
尝试一下
reset
tset
命令,
stty sane
在我们的测试中能够按照预期工作,而
reset
tset
的修复过程更彻底。
19.9.4
 参考
man reset
man stty
man tset
10.7
19.10
 用空变量删除文件
19.10.1
 问题
你认为某个已有变量中保存的是待删除的文件列表,可能要在脚本运行后做清理之用。但
事实上,这是一个空变量,要坏事的。
19.10.2
 解决方案
不要做:
rm -rf $files_to_delete
千万不要做:
rm -rf /$files_to_delete
应该这样做:
[ -n "$files_to_delete" ] && rm -rf $files_to_delete ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

bash 网络安全运维

bash 网络安全运维

Paul Troncone, Carl Albing
Linux 内核观测技术BPF

Linux 内核观测技术BPF

David Calavera, Lorenzo Fontana

Publisher Resources

ISBN: 9787115553782