Bash

擷取 subshel l 命令替換輸出

  • June 20, 2017

我正在嘗試擷取命令替換的輸出。這一直有效,直到將管道添加到命令中。我做錯了什麼還是這是mingw的怪癖?

$ bash --version
GNU bash, version 4.3.46(2)-release (x86_64-pc-msys)
$ echo $(ls | wc -l)
23
$ test=$(ls | wc -l); echo test="$test"
test=

這看起來像 mingw 的一個怪癖:

$ test=$(ls | wc -l); echo test="$test"
test=45
$ bash --version
GNU bash, version 4.3.43(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

引用自:https://unix.stackexchange.com/questions/372067