`
- 浏览:
235235 次
- 性别:
- 来自:
北京
-
- echo 命令可以显示文本行或变量 或者把字符串输入到文件
echo [option] string
-- -e 解析转义字符
-- -n 回车不换行 linux系统默认回车换行
-- 转义符(\c, \f, \t, \n)
echo "Theo log files have all been done" > mylogfile.txt
该命令可用于在脚本打印一些错误信息。
- read 可以从键盘或文件的某一行文本中读入信息 并将其赋给一个变量
read variable1 varible2
-- 如果只指定了一个变量,那么read将会把所有的输入赋给该变量,真到遇到第一个
文件结束符或回车;如果给出了多个变量,它们按顺序分别被赋对不同的变量。
shell将用空格作为变量之间的分隔符。
- cat 是一个简单而通用的命令,可以用它来显示文件内容,创建文件,还可以用它来
显示控制字符。
cat [options] filename1 ... filename2 ..
-- -v 显示控制字符(例如dos中的某些字符)
-- 使用该命令时要注意,它不会在文件分页符处停下来;它会一下显示完整个文件
。如果希望每次显示一页,可以使用more命令或把cat命令的输出通过管道
传递到另外一个具有分页功能的命令(more,less)中。
-- cat myfile1 myfile2 myfile3 > myfile
- 管道(|) 一个命令的输出做为别外一个命令的输入
-- df -k|awk '{print $1}'|grep -v "Filesystem"
- tee命令把输出的一个副本输送到标准输出,另一个副本拷贝到相应的文件中。
-- tee -a files
--如果希望在看到输出的同时,也将其存入一个文件,这个命令再适合不过。
--一般用于管道之后。
- exec命令可以用来替代当前shell;换句话说,并没有启动子shell。使用这一命令
时任何现有环境都会被清除,并重新启动一个shell.
标准输入,输出和错误
- 在shell中执行命令时,每个进程都和三个打开的文件相联系,并使用文件描述符来
引用这些文件。由于文件描述符不容易记忆,shell同时也给出了相应的文件名。
文件 ----------------- --------------文件描述符
输入文件 -- 标准输入 | 0(缺省是键盘,也可以是文件或其它命令的输出)
输出文件 -- 标准输出 | 1(缺省是屏幕,也可以是文件)
错误文件 -- 标准错误 | 2(缺省是屏幕,也可以是文件)
- 系统中实际上有12个文件描述符,可以任意使用文件描述符3到9。
- 改变程序运动的输入和输出
command > filename 把标准输出重定向到一个新文件中
command >> filename 同上(追加)
command 1 > filename 把标准输出重定向到一个文件中
command > filename 2>&1 把标准输出和错误一起重定向到一个文件
command 2 >filename 把标准错误重定向到一个文件
command 2 >> filename 把标准错误重定向到一个文件(追加)
command >> filename 2>&1 把标准输出和错误一起重定向到一个文件(追加)
command < filename > filename2 filename标准输入 f..2为标准输出
command < filename 以filename为文件作为标准输入
command << delimiter 从标准输入中读入直到遇到delimiter分界符
command < &m 把文件描述符m做为标准输入
command > &m 把文件描述符m做为标准输出
command <&- 关闭标准输入
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
• 使用标准输入、标准输出及标准错误。 • 重定向标准输入和标准输出。 本章全面讨论了s hell对数据和信息的标准输入、标准输出,对重定向也做了一定的介绍。
Redirect input, output, and errors of a command or script execution to other streams Debug code with different shell debugging techniques to make your scripts bug-free Manage processes, along with the...
Input/Output and Command-Line Processing Chapter 8. Process Handling Chapter 9. Debugging Shell Programs Chapter 10. bash Administration Chapter 11. Shell Scripting Chapter 12. bash for Your System ...
Chapter Two: Input, Output, and Throughput Chapter Three: Looping and Branching Chapter Four: Command-Line Parsing and Expansion Chapter Five: Parameters and Variables Chapter Six: Shell Functions ...
concourse_input_output
Shell scripting is a way to harness and customize the power of any Unix system, and an essential skill for Unix users, system administrators, and even professional Mac OS X developers. But beneath ...
Reading the output of a sequence of commands 38 Reading "n" characters without pressing Return 40 Field separators and iterators 41 Comparisons and tests 44 Chapter 2: Have a Good Command 49 ...
You'll also explore the kernel and examine key system tasks inside user space, including system calls, input and output, and filesystems. With its combination of background, theory, real-world ...
shell. Then, you'll learn how to write a simple bash script and how to edit your bash script using Linux editors. Following this, you will learn how to define a variable and the visibility of a ...
Your First Shell Program * Input, Output, and Throughput * Looping and Branching * Command-Line Parsing and Expansion * Parameters and Variables * Shell Functions * String Manipulation * File ...
Your First Shell Program * Input, Output, and Throughput * Looping and Branching * Command-Line Parsing and Expansion * Parameters and Variables * Shell Functions * String Manipulation * File ...
用函数实现希尔(shell)排序,并输出每趟排序的结果,初始增量d=n/2,其后d=d/2 Input 第一行:键盘输入待排序关键的个数n 第二行:输入n个待排序关键字,用空格分隔数据 Output 每行输出一趟排序结果,数据之间用一个...
Shell Basics Module 7 — Shell Advanced Features Module 8 — File Name Generation Module 9— Quoting Module 10 — Input and Output Redirection Module 11 — Pipes Module 12 — Using ...
Manage real-time input/output (I/O) Work at the Linux I/O level with shell commands, Python, and C Compile and install Linux kernels Work at a high level with JavaScript and the BoneScript library ...
Use standard input and output, redirection, and pipelines Edit files with Vi, the world's most popular text editor Write shell scripts to automate common or boring tasks Slice and dice text files with...
and process management * Use standard input and output, redirection, and pipelines * Edit files with Vi, the world's most popular text editor * Write shell scripts to automate common or boring tasks ...
and process management * Use standard input and output, redirection, and pipelines * Edit files with Vi, the world's most popular text editor * Write shell scripts to automate common or boring tasks ...
Shell scripting is a way to harness and customize the power of any Unix system, and an essential skill for Unix users, system administrators, and even professional Mac OS X developers. But beneath ...
You’ll also explore the kernel and examine key system tasks inside user space, including system calls, input and output, and filesystems. With its combination of background, theory, real-world ...
How and why to redirect input and output from applications. How to customize your shell prompt. How to be efficient at the command line by using aliases, tab completion, and your shell history. How...