当前位置:网站首页>A simple bash to powershell case
A simple bash to powershell case
2022-07-31 05:58:00 【tcliuwenwen】
博文背景
群友的bash脚本需要移植到Windows平台下,我帮群友写了一下
具体操作
脚本未经过充分测试,很可能有BUG存在
#!/bin/bash
FILE_NAME=$1
NEW_ORG_NAME=$2
STR=`sed -n '1p' ./${
FILE_NAME}`
TEMP_STR=($STR)
BLOCKCHAIN_NAME=${TEMP_STR[1]}
STR=`sed -n '3p' ./${
FILE_NAME}`
TEMP_STR=($STR)
CRYTPO_PATH=${TEMP_STR[1]}
ADDORG_PEER=`expr $# - 2`
#ADDORG_PEER=`expr ${ADDORG_PEER} / 2`
STR=[email protected]
ARG_ARR=($STR)
function addOrg(){
line=`sed -n '/organizations:/=' ${
FILE_NAME} | tail -n1`
echo " ${NEW_ORG_NAME}: #TAGORGS:_${NEW_ORG_NAME} mspid: ${NEW_ORG_NAME} #TAGORGS:_${NEW_ORG_NAME} cryptoPath: ${CRYTPO_PATH}/peerOrganizations/${NEW_ORG_NAME}/users/[email protected]${NEW_ORG_NAME}/msp #TAGORGS:_${NEW_ORG_NAME} peers: #${NEW_ORG_NAME} #TAGORGS:_${NEW_ORG_NAME}" > temp.txt
# for ((i=2;i<`expr ${ADDORG_PEER} + 2`;i++));do
# echo " - ${ARG_ARR[i]}" >> temp.txt
# done
sed -i "${line} r temp.txt" ${FILE_NAME}
}
addOrg
$FILE_NAME=$args[0]
$NEW_ORG_NAME=$args[1]
$STR=$(Get-Content $FILE_NAME | Select -Index 0)
$TEMP_STR=$STR.Split(" ")
$BLOCKCHAIN_NAME=$TEMP_STR[1]
$STR=$(Get-Content $FILE_NAME | Select -Index 2)
$TEMP_STR=$STR.Split(" ")
$CRYTPO_PATH=$TEMP_STR[1]
$ADDORG_PEER=$args.Count - 2
$STR=$args
$ARG_ARR=$STR
Function addOrg() {
$linenumber=$(Get-Content ${
FILE_NAME} | Select-String -Pattern "organizations:" | Select-Object LineNumber)
$line=$linenumber.Get($linenumber.Length-1).LineNumber
echo @" ${NEW_ORG_NAME}: #TAGORGS:_${NEW_ORG_NAME} mspid: ${NEW_ORG_NAME} #TAGORGS:_${NEW_ORG_NAME} cryptoPath: ${CRYTPO_PATH}/peerOrganizations/${NEW_ORG_NAME}/users/[email protected]${NEW_ORG_NAME}/msp #TAGORGS:_${NEW_ORG_NAME} peers: #${NEW_ORG_NAME} #TAGORGS:_${NEW_ORG_NAME} "@ | Set-Content temp.txt
# 此处缺一个sed命令暂时没有实现
}
addOrg
边栏推荐
猜你喜欢
随机推荐
js中的对象与函数的理解
Markdown 帮助文档
2021年京东数据分析工程师秋招笔试编程题
Powershell中UTF-8环境中文乱码解决办法
The MySQL database in Alibaba Cloud was attacked, and the data was finally recovered
cocoscreator 显示刘海内容
【云原生】微服务Nacos的简单介绍与使用
cocos2d-x-3.2创建项目方法
Eternal blue bug reappears
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]
【云原生】开源数据分析 SPL 轻松应对 T+0
Sqlite A列数据复制到B列
为什么redis是单线程还那么快?
js中的函数
cocos2d-x-3.2 Physics
cocos2d-x-3.x 修改和纪录
Digital twins will be an important way to enter the "metaverse"
js中的this指向与原型对象
Several solutions for mysql startup error The server quit without updating PID file
Judgment of database in SQL injection





![[swagger close] The production environment closes the swagger method](/img/43/17be22626ba152b33beaf03f92fbec.png)



