linux - 输入命令时更改命令提示符

标签 linux

我需要能够更改运行 c 文件的可执行文件时的提示以获得自定义提示

例如:

$ abc

abc>

在这里用户可以给出程序可接受的命令。 我看到这种情况发生在像 MySQL 这样的程序上,我想知道是否可以这样做。

最佳答案

您可以使用 gnu readline用于自定义提示

#include <readline/readline.h>
#include <readline/history.h>


while (1)
{
   command = readline ("$abc");
   command = readline ("abc>");
   //validate your command name
   system(command);
   add_history (command); ///add command in history
}

关于linux - 输入命令时更改命令提示符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22347840/

相关文章:

c++ - QProcess -> 在 Linux 上从 sftp 读取标准输出

linux - 当 rm 文件但硬链接(hard link)仍然存在时,inode 将被标记为 "unused"?

c - 在多线程应用程序中,如何根据线程在单独的文件中重定向 stderr 和 stdout?

linux - 如何使用斜杠修改配置参数值

linux - 将访问文件的进程的 pid 交叉引用到调用该文件的进程

linux - 使用 ssh 从文件中删除 eval base64_decode

linux - TCP/IP : set socket option for keep-alive after connection has been established

mysql - 如何使 Mysql/Mariadb 脚本在 debian 启动时工作?

c++ - 如何使用 syslog.h 将消息发送到远程系统日志

php - 使用 PHP 将 Powerpoint PPT 转换为 JPG 或 PNG 图像