AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-963195

M. Fachrizal Utama's questions

Martin Hope
M. Fachrizal Utama
Asked: 2024-07-25 12:08:08 +0800 CST

为什么 shell 脚本中的“readonly”命令不能读取“HISTFILE”变量?

  • 5

当我在 bash shell 中运行以下命令时:

if [[ $(readonly | cut -d= -f1 | grep -qo HISTFILE && echo $?) == 0 ]]; then sudo grep -iwo "readonly HISTFILE" /etc/profile /etc/profile.d/*; else echo "HISTFILE not set or not set properly"; fi

上面的命令返回了我想要的结果,即:

/etc/profile.d/os-security.sh:readonly HISTFILE

但是当我将上述命令放入 shell 脚本中时,结果发生了变化,即:

HISTFILE not set or not set properly

这里是完整的外壳:

[ansible@rhel8-hardening-test ~]$ if [[ $(readonly | cut -d= -f1 | grep -qo HISTFILE && echo $?) == 0 ]]; then sudo grep -iwo "readonly HISTFILE" /etc/profile /etc/profile.d/*; else echo "HISTFILE not set or not set properly"; fi
/etc/profile.d/os-security.sh:readonly HISTFILE
[ansible@rhel8-hardening-test ~]$ 
[ansible@rhel8-hardening-test ~]$ 
[ansible@rhel8-hardening-test ~]$ 
[ansible@rhel8-hardening-test ~]$ cat test.sh 
#!/bin/bash

if [[ $(readonly | cut -d= -f1 | grep -qo HISTFILE && echo $?) == 0 ]]; then sudo grep -iwo "readonly HISTFILE" /etc/profile /etc/profile.d/*; else echo "HISTFILE not set or not set properly"; fi
[ansible@rhel8-hardening-test ~]$ 
[ansible@rhel8-hardening-test ~]$ 
[ansible@rhel8-hardening-test ~]$ 
[ansible@rhel8-hardening-test ~]$ bash test.sh 
HISTFILE not set or not set properly
[ansible@rhel8-hardening-test ~]$ 

当我使用上述命令的 shell 脚本时,如何才能获得与当前 shell 相同的结果?

bash
  • 1 个回答
  • 37 Views
Martin Hope
M. Fachrizal Utama
Asked: 2024-02-29 12:09:15 +0800 CST

如何将文本文件从 BASH 转换为 HTML?

  • 5

我已经使用下面的命令“systemctl status ddos​​.service”从 bash 中提取了一些文本:

在此输入图像描述

但是,当我为上面提取的文本生成 html 格式的报告时,它会在一行中显示所有文本,如下面的捕获:

在此输入图像描述

我的问题是:我们如何将 html 报告中的结果与 bash 中的结果相同?(我的意思是,html 报告中的结果不是像我上面捕获的 html 报告一样在一行中,但我想在 HTML 报告中捕获,就像 bash 中的结果一样)

linux
  • 1 个回答
  • 29 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve