当前位置:网站首页>一个简单的bash转powershell案例
一个简单的bash转powershell案例
2022-07-31 05:11: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
边栏推荐
- MySQL compressed package installation, fool teaching
- The server time zone value ‘й‘ is unrecognized or represents more than one time zone
- Build vulhub vulnerability shooting range on kali
- 【云原生】SQL(及存储过程)跑得太慢怎么办?
- js中的对象与函数的理解
- 04 【计算属性 侦听属性】
- 元宇宙的前景及四大赛道
- MySQL高级语句(一)
- js中的全局作用域与函数作用域
- gin框架学习-Gin框架和Gorm框架搭建一个简单的API微服务
猜你喜欢

Linux中mysql密码修改方法(亲测可用)

Take you to understand the MySQL isolation level, what happens when two transactions operate on the same row of data at the same time?

【uiautomation】微信好友列表获取(存储到txt中)

DeFi Token in the project management

场效应管 | N-mos内部结构详解

NFT:数字所有权的核心

继承、Super,重写、抽象类、抽象方法 1(第七天)

11 【定位】

【ubuntu20.04安装MySQL以及MySQL-workbench可视化工具】

阿里云中mysql数据库被攻击了,最终数据找回来了
随机推荐
leetcode-每日一题剑指 Offer II 041. 滑动窗口的平均值(队列模拟)
GUCCI, LV and other luxury giant universe how to layout yuan, other brands should keep up with?
(Crypto必备干货)详细分析目前NFT的几大交易市场
SQL注入中数据库的判断
The server time zone value ‘й‘ is unrecognized or represents more than one time zone
阿里一面,说说你知道消息中间件的应用场景有哪些?
The feign call fails, JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
MySQL高级SQL语句(二)
Linux中mysql密码修改方法(亲测可用)
一文速学-玩转MySQL获取时间、格式转换各类操作方法详解
The MySQL database in Alibaba Cloud was attacked, and the data was finally recovered
js中的this指向与原型对象
About integrating superset into your own project
this指向问题
Regular Expression Basics
07 【内置指令 自定义指令】
leetcode-每日一题1252. 奇数值单元格的数目(模拟优化)
[windows]--- SQL Server 2008 super detailed installation tutorial
js中的函数
npm WARN config global `--global`, `--local` are deprecated. Use `--location solution