我的$PATH
中保存了这个shell脚本(由文件名depends
调用):
#!/bin/bash
for i in "$@"
do
depends=+("nodejs-$i")
done
echo $depends
输入(即$@
)的格式如下:
'flatten' 'once' 'is-file' 'multistream' 'piece-length' 'junk' 'xtend' 'bencode' 'readable-stream' 'run-parallel 'filestream' 'simple-sha1' 'minimist' 'block-stream2'
是的。因此,我希望能够编写一个package.json
文件中列出的依赖项,该文件包含在这个Python脚本的DEP
列表变量中(文件名为npm2.py
):
import json
from sys import argv
print(argv[1])
from subprocess import call
with open("/home/fusion809/OBS/home:fusion809:arch_extra/nodejs-" + argv[1] + "/src/package/package.json") as json_file:
json_data = json.load(json_file)
deps = json_data["dependencies"]
LEN=len(deps)
print(LEN)
i=0
DEP=list()
print(DEP)
for key, value in deps.items():
print(key)
DEP.append(key)
i = i+1
print(i)
#call(["cpobsn", key, argv[1]])
print(DEP)
call("depends", DEP) # returns errors as DEP is a list!
一个新变量,比如说DEPS
,这样它就可以作为depends
shell脚本的输入。如果有帮助的话,这里是我当前的DEP
变量,我想将其转换为前面显示的标准输出:
['flatten', 'once', 'is-file', 'multistream', 'piece-length', 'junk', 'xtend', 'bencode', 'readable-stream', 'run-parallel', 'filestream', 'simple-sha1', 'minimist', 'block-stream2']
因此,我要问的是如何将Python列表转换为shell可读的空间分隔字符串集。你知道吗
^{} 将其参数放在一个列表中。尝试:
相关问题 更多 >
编程相关推荐