Har*_*rev 9 bash shell command-line command-line-arguments brace-expansion
当我需要使用不同的参数多次运行命令时,我使用了这种方法(完全不了解它):
touch {a,b,c}
这相当于:
touch a
touch b
touch c
我认为使用以下循环可以实现同样的目的:
for file in {a,b,c}; do touch $file; done
但是,我偶然发现了一个不起作用的情况:
pear channel-discover {"pear.phpunit.de","pear.symfony-project.com"}
我有几个问题:
Sha*_*hin 12
这称为Brace Expansion,它扩展为给定字符串的空格分隔列表.
所以touch {a,b,c}相当于
touch a b c
虽然touch {a,b,c}x相当于:
touch ax bx cx
您的pear命令基本上将运行为:
pear channel-discover pear.phpunit.de pear.symfony-project.com
这可能不是你的预期.如果您希望为每个字符串运行一次命令,请使用for循环(它回答您的第二个问题),或使用大括号扩展和xargs的组合.
问题是与你的期望相反,支撑扩张了
touch {a,b,c}
相当于
touch a b c   # NOT 3 separate invocations.
(echo {a,b,c}用于验证).似乎pear channel-discover不接受两个 args.您可能会看到相同的错误
pear channel-discover pear.phpunit.de pear.symfony-project.com
| 归档时间: | 
 | 
| 查看次数: | 5950 次 | 
| 最近记录: |