linux - bash:命令在终端中工作,而不是在脚本中工作

标签 linux bash newline

我在做

a="$(openssl x509 -in /path/to/pemfile.pem -text -noout)";
echo ${a} |grep -a1 -b2 Signature

如果我将这条线放入终端,效果会很好

但是,如果我将同一行放在文件 executeme.sh, chmod +x executeme.sh, ./executeme.sh

我似乎没有在变量中创建换行符,导致 grep 只接收一行。终端输出如下:

20- Version: 3 (0x2)
38- Serial Number: 32 (0x27)
64: Signature Algorithm: md5WithRSAEncryption
107- Issuer: C=EN, ST=a, L=b, O=c, OU=d, CN=e
244- Validity
------
[...]

脚本输出整个证书,就好像我只会做 a="$(openssl ...)";回显 ${a}

最佳答案

echo "${a}" |grep -a1 -b2 Signature #mind the double quotes

为什么要用双引号?

参见 [ this ]回答 + [ this ]回答。

关于linux - bash:命令在终端中工作,而不是在脚本中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38473531/

相关文章:

bash - 在 bash 中使用 IFS 而不是空格

javascript - JS正则表达式按行分割

Java:每第 309 个字符后插入换行符

python - 在linux上使用python编写带有DOS行尾的文本文件

正则表达式匹配特殊字符的精确出现

c - Linux内核模块编程中_do_fork()的问题

linux - 通过指定行号显示单行?

linux - MD5重复消除错误

c# - 迁移到 netcore 2.0 会导致 Linux 和 Mac 上的 System.IO.Filesystem 出现问题

linux - 如何查找目录组合