- 論壇徽章:
- 2
|
- Command Substitution
- Command substitution allows the output of a command to replace the command name. There are two forms:
- $(command)
- or
- `command`
- Bash performs the expansion by executing command and replacing the command substitution with the standard output of the
- command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word
- splitting. The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).
復(fù)制代碼 執(zhí)行``的時(shí)候,會(huì)把里面的換行用空格替換掉。- yu@yu-vm:~/0513$ awk '{print $1}' 1.txt
- a
- b
- c
- d
- a
- b
- a
- c
- yu@yu-vm:~/0513$ echo `awk '{print $1}' 1.txt`
- a b c d a b a c
- yu@yu-vm:~/0513$ echo "`awk '{print $1}' 1.txt`"
- a
- b
- c
- d
- a
- b
- a
- c
- yu@yu-vm:~/0513$
復(fù)制代碼 至于ls為啥單獨(dú)執(zhí)行的時(shí)候不會(huì)換行,這個(gè)man ls也沒查到。期待大神來解答下
|
|