Skip to Content
Linux 使用和管理指南:从云原生到可观测性
book

Linux 使用和管理指南:从云原生到可观测性

by Michael Hausenblas
May 2024
Intermediate
232 pages
7h 11m
Chinese
China Machine Press
Content preview from Linux 使用和管理指南:从云原生到可观测性
shell
和脚本
|
65
如,用一个选项菜单。此外,与其使用
echo
,不如考虑
printf
,它允许你对输出进行
精细的控制,包括颜色。
下面是一个高级
I/O
的使用实例:
read name
printf "Hello %s" "$name"
从用户输入中读取数值。
输出上一步读取的值。
还有其他更高级的概念供你参考,如信号和陷阱(
https://oreil.ly/JsV1v
。鉴于我们
在这里只想提供一个关于脚本主题的概述和介绍,我将向你推荐优秀的
bash Scripting
Cheatsheet
https://oreil.ly/nVjhN
,以获得所有相关结构的全面参考。如果你对编写
shell
脚本很认真,我建议你阅读
Carl Albing
JP Vossen
Cameron Newham
编写的
bash Cookbook
,其中包含了很多很好的片段,你可以把它作为一个起点。
3.4.2
编写可移植的
bash
脚本
我们现在来看看在
bash
中编写可移植的脚本是什么意思。但是,可移植又是什么意思,
你为什么要关心这个问题?
3.1.2
节的开头,我们定义了
POSIX
的含义,所以让我们在此基础上进行探讨。当我
说“可移植”时,我的意思是我们不对脚本的执行环境做太多的假设
无论是隐含的
还是显性的。如果一个脚本是可移植的,它就可以在许多不同的系统(
shell
Linux
行版等)上运行。
但是请记住,即使你确定了
shell
的类型(在我们的例子中是
bash
,也不是所有的功能
都能在不同版本的
shell
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

CISSP, 4th Edition

CISSP, 4th Edition

Sari Greene

Publisher Resources

ISBN: 9787111755333