- Bash Quick Start Guide
- Tom Ryder
- 313字
- 2021-07-23 16:58:56
Shell metacharacters
So far, all of our examples of commands and arguments have been single unquoted shell words. However, there is a set of metacharacters that have a different meaning to Bash, and trying to use them as part of a word causes problems.
For example, suppose you want to create (touch) a new file named important file. Note that there's a space in the name. If you try to create it as follows, you get unexpected results:
$ touch important file
If we list the files in the directory after running this, using ls -1 to put all the names on separate lines, we can see we've actually created two files; one named important, and one named file:
$ ls -1 file important
This happened because the space between the two words separated them into two separate arguments. Space, tab, and newline are all metacharacters. So are | (pipe), & (ampersand), ; (semicolon), ( and ) (parentheses), and < and > (angle brackets).
Even the error messages can be confusing if you try to use a word with one of these characters in it:
$ touch Testfile<Tom>.doc bash: Tom: No such file or directory $ touch Review;Final.doc bash: Final.doc: command not found
In some cases, you may not get an error message at all, and something very unexpected will happen instead; for example:
$ touch $$$Money.doc $ ls 31649.doc
A lot of the time we can simply work with files and words that don't use these characters. However, we can't always do that, and we can't just hope others behave the same way—we will eventually have to work with their files and data. How can we include special characters in our words safely?
- 樂(lè)高機(jī)器人:WeDo編程與搭建指南
- Cinema 4D R13 Cookbook
- Mastering VMware vSphere 6.5
- WOW!Illustrator CS6完全自學(xué)寶典
- 流處理器研究與設(shè)計(jì)
- Expert AWS Development
- 城市道路交通主動(dòng)控制技術(shù)
- Multimedia Programming with Pure Data
- 大學(xué)計(jì)算機(jī)應(yīng)用基礎(chǔ)
- LAMP網(wǎng)站開發(fā)黃金組合Linux+Apache+MySQL+PHP
- RedHat Linux用戶基礎(chǔ)
- 啊哈C!思考快你一步
- Visual Studio 2010 (C#) Windows數(shù)據(jù)庫(kù)項(xiàng)目開發(fā)
- Windows安全指南
- 基于RPA技術(shù)財(cái)務(wù)機(jī)器人的應(yīng)用與研究