当前位置:网站首页>一个简单的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
边栏推荐
- vulhub靶场学习日记hackme2
- About integrating superset into your own project
- MySQL compressed package installation, fool teaching
- The MySQL database in Alibaba Cloud was attacked, and the data was finally recovered
- 10 【高度塌陷与BFC】
- npm WARN config global `--global`, `--local` are deprecated. Use `--location解决方案
- 计网 Packet Tracer仿真 | 简单易懂集线器和交换机对比(理论+仿真)
- leetcode-每日一题745. 前缀和后缀搜索(哈希和字典树)
- mysql password modification method in Linux (pro-test available)
- Object,多态 1(第八天)
猜你喜欢

DeFi Token in the project management

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

GUCCI、LV等奢侈品巨头如何布局元宇宙的,其他品牌应该跟上吗?
![[windows]--- SQL Server 2008 super detailed installation tutorial](/img/b7/dc802c63b07edc4298b6e6b90d865c.png)
[windows]--- SQL Server 2008 super detailed installation tutorial

年终总结——岁月静好~

leetcode-每日一题剑指 Offer II 041. 滑动窗口的平均值(队列模拟)

MySQL错误-this is incompatible with sql_mode=only_full_group_by完美解决方案

对js的数组的理解

Three-party login using wallet Metamask based on web3.0
初识正则表达式
随机推荐
leetcode-每日一题565. 数组嵌套(标记图和并查集)
File operations in C language (1)
The server time zone value ‘й‘ is unrecognized or represents more than one time zone
05 【绑定样式 条件渲染 列表渲染】
数据库 | SQL增删改查基础语法
5 methods of MySQL paging query
sqlmap注入教程 常用指令
feign调用不通问题,JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
Volatility取证工具使用日记
How MySQL - depots table?A look at will understand
The feign call fails, JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
[windows]--- SQL Server 2008 super detailed installation tutorial
MySQL压缩包方式安装,傻瓜式教学
leetcode-每日一题1217. 玩筹码(贪心+位运算)
Xiaobai learns reptiles - introduction to reptiles
leetcode-每日一题735. 行星碰撞(栈模拟)
this指向问题
11 【组件通信】
动态规划(一)| 斐波那契数列和归递
MySQL高级语句(一)