我有一个简单的文本文件,我需要一个powershell脚本来替换文件内容的某些部分.
我目前的脚本如下:
$content = Get-Content -path "Input.json"
$content -Replace '"(\d+),(\d{1,})"', '$1.$2' | Out-File "output.json"
Run Code Online (Sandbox Code Playgroud)
是否可以在没有内容变量的情况下将其写入一行,如下所示?
Get-Content -path "Input.json" | ??? -Replace '"(\d+),(\d{1,})"', '$1.$2' | Out-File "output.json"
Run Code Online (Sandbox Code Playgroud)
我不知道如何在没有$ content变量的情况下在第二个命令中使用第一个get-content命令行开关的输出?是否有自动PowerShell变量
是否有可能比管道中的替换更多.
Get-Content -path "Input.json" | ??? -Replace '"(\d+),(\d{1,})"', '$1.$2' | ??? -Replace 'second regex', 'second replacement' | Out-File "output.json"
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的测试模拟函数fs.readdir.
起初我曾尝试使用sinon,因为这是一个非常好的框架,但是没有用.
stub(fs, 'readdir').yieldsTo('callback', { error: null, files: ['index.md', 'page1.md', 'page2.md'] });
Run Code Online (Sandbox Code Playgroud)
我的第二次尝试是使用自替换函数来模拟函数.但它也行不通.
beforeEach(function () {
original = fs.readdir;
fs.readdir = function (path, callback) {
callback(null, ['/content/index.md', '/content/page1.md', '/content/page2.md']);
};
});
afterEach(function () {
fs.readdir = original;
});
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我为什么两者都不起作用?谢谢!
更新 - 这也不起作用:
sandbox.stub(fs, 'readdir', function (path, callback) {
callback(null, ['index.md', 'page1.md', 'page2.md']);
});
Run Code Online (Sandbox Code Playgroud)
UPDATE2:
当我试图在我的测试中直接调用此函数时,我最后一次尝试模拟readdir函数正在工作.但是当我在另一个模块中调用mocked函数时.
我是macosx上的shell编程的新手,并且有一点问题.我编写了以下shell脚本:
#!/bin/sh
function createlink {
source_file=$1
target_file="~/$source_file"
if [[ -f $target_file ]]; then
rm $target_file
fi
ln $source_file $target_file
}
createlink ".netrc"
Run Code Online (Sandbox Code Playgroud)
当我执行这个脚本时,我收到消息ln:〜/ .netrc:没有这样的文件或目录,我不知道为什么会这样!你看到错误吗?谢谢!
我想阻止 git push 和 pull 到所有远程分支。我知道开关 --all 并且我希望当我设置这个开关时 git 只会推送到 all 。
当我输入git remote show origin时,我看到所有本地分支都配置为 git pull 并推送到远程分支。
但我更喜欢它,当我输入git pull without originbranchname时,git 只会推送实际分支。
是否有一个配置开关可以改变这种行为?