简体   繁体   English

Linux命令替换$(cat…)混乱

[英]Linux command substitution $(cat …) confusion

I am configuring NPM to use TLS (this is unrelated). 我正在将NPM配置为使用TLS(这是无关的)。 I have some confusion with how the command substitution in BASH works.. 我对BASH中的命令替换如何工作有些困惑。

I am issuing the following commands npm config set cert "$(cat public.pem)" 我正在发出以下命令npm config set cert "$(cat public.pem)"

This command works as intended setting the cert field in my .npmrc to the contents of public.pem 此命令按预期工作,将我的.npmrc中的cert字段设置为public.pem的内容

Next I issue the command npm config set key "$(cat private.pem)" 接下来,我发出命令npm config set key "$(cat private.pem)"

This command fails silently and sets the key field in my .npmrc to empty. 该命令无提示失败,并将.npmrc中的key字段设置为空。

It seems the private key file starts with the standard -----BEGIN RSA PRIVATE KEY----- and my public key starts with Bag Attributes. 似乎私钥文件以标准-----BEGIN RSA PRIVATE KEY-----开头,而我的公钥以Bag Attributes开头。 It seems the file starting with dashes is messing up my command substitution. 似乎以破折号开头的文件弄乱了我的命令替换。

Thoughts? 思考?

Where did the cat go in the failing command? cat在失败的命令中去了哪里?

npm config set key "$(cat private.pem)"

Note that you can also use 请注意,您也可以使用

$(< private.pem)

which should be a bit faster than calling cat . 这应该比打电话给cat快一点。

After a little more research this isn't a problem with command substitution. 经过更多研究后,这对于命令替换不是问题。 npm config set.... seems to ignore input that starts with dashes. npm config set....似乎忽略了以破折号开头的输入。

npm config set key ---- fails whereas npm config set key 1234 works npm config set key ----失败,而npm config set key 1234有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM