我chcp 65001在Windows shell中遇到命令问题.
我需要生成文件夹中的文件列表.所以我运行cmd.exe,输入
cd folder
dir /B /O:N > list_of_files.txt
Run Code Online (Sandbox Code Playgroud)
它工作,但我遇到了一些特殊的非ASCII字符的问题,这些字符在某些文件名中.所以我补充道
chcp 65001
一切正常,但当我将这些命令放入.bat文件时,脚本不起作用.
所以
cd folder
chcp 65001
dir /B /O:N > list_of_files.txt
Run Code Online (Sandbox Code Playgroud)
不生成列表.
和
cd folder
chcp 65001 && dir /B /O:N > list_of_files.txt
Run Code Online (Sandbox Code Playgroud)
以及
cd folder
chcp 65001 > nul && dir /B /O:N > list_of_files.txt
Run Code Online (Sandbox Code Playgroud)
生成列表,但使用默认编码:/.
一切都在cmd.exe中工作,但不在.bat文件中.
我已经阅读了主题:stackoverflow.com/questions/2182568/batch-script-is-not-executed-if-chcp-was-called,但它没有帮助.
编辑:我部分解决了我的问题,改为chcp 65001,chcp 1250因为所有字符都在这个编码.但实际上这并没有回答这个问题.
我写了一个脚本
#!/bin/bash
commit_msg=$1
echo "Your commit message: $commit_msg"
Run Code Online (Sandbox Code Playgroud)
在hooks/commit-msg该验证中提交消息
git commit -m "fixed a bug"
Run Code Online (Sandbox Code Playgroud)
但是当我运行钩子时,我有:
Your commit message: .git/COMMIT_EDITMSG
Run Code Online (Sandbox Code Playgroud)
代替
Your commit message: fixed a bug
Run Code Online (Sandbox Code Playgroud)
如何将提交消息捕获到变量中?
我已经阅读了如何捕获 git commit 消息并运行一个操作,
但它对我没有帮助,因为那个钩子是为了post-receive我需要它,commit-msg所以我没有我的提交消息
git log -1 HEAD --pretty=format:%s
Run Code Online (Sandbox Code Playgroud)
因为我的钩子阻止了提交。
我尝试在 Access 中使用 SQL 查询,但它不起作用。为什么?
SELECT * FROM table
EXCEPT
SELECT DISTINCT name FROM table;
Run Code Online (Sandbox Code Playgroud)
FROM 语句中有语法错误。
我想通过修改最后的所有"a"来改变所有出现的事件,如"waaa","wwwaaaaa","wa".
waaa> w
wwa> ww
waaaaa> w
我知道如何使用正则表达式在文本中找到这些字符串:
grep -nE "wa+" file.txt
Run Code Online (Sandbox Code Playgroud)
我也知道如何在bash脚本中更改一个字符串
#!/bin/bash
s1="wwwwaaaaaaaa"
s2=${s1%w*}
echo "$s1 --> $s2"
Run Code Online (Sandbox Code Playgroud)
(修改后的脚本来自/sf/answers/1936110221/)
但是我想使用像
sed -E 's/wa+/ZZZ/' file.txt
Run Code Online (Sandbox Code Playgroud)
ZZZ是我需要的东西.
sed -E 's/wa+/${$1%w*}/' file.txt
Run Code Online (Sandbox Code Playgroud)
不起作用.
样本输入:
Lorem ipsum wa waaaaaaa saaa dolor sit amet, consectetur aw awwwwaaaa adipiscing elit
理想的输出:
Lorem ipsum w w saaa dolor sit amet, consectetur aw awwww adipiscing elit
bash ×2
batch-file ×1
cmd ×1
command-line ×1
git ×1
githooks ×1
ms-access ×1
regex ×1
sed ×1
sql ×1