Fwd: [Bug 79628] minicli always uses /bin/sh, even if user sets SHELL
David Faure
faure at kde.org
Wed Apr 14 12:48:00 BST 2004
Can someone who knows about shells comment on this patch?
---------- Forwarded Message ----------
Subject: [Bug 79628] minicli always uses /bin/sh, even if user sets SHELL
Date: Wednesday 14 April 2004 13:45
From: Jonathan Marten <jonathan.marten at uk.sun.com>
Patch to use SHELL from environment if available
Also cleans up the command line generation and shell quoting.
--- kdebase/kdesktop/minicli.cpp.orig 2004-01-17 12:47:58.000000000 +0000
+++ kdebase/kdesktop/minicli.cpp 2004-04-14 12:13:32.789746000 +0100
@@ -31,6 +31,7 @@
#include <pwd.h>
#include <string.h>
#include <errno.h>
+#include <stdlib.h>
#include <qvbox.h>
#include <qlabel.h>
@@ -327,6 +328,13 @@
QDialog::keyPressEvent( e );
}
+static const char *getShell(void)
+{
+ const char *sh = getenv("SHELL");
+ if (sh==NULL) sh = "/bin/sh";
+ return (sh);
+}
+
QString Minicli::terminalCommand (const QString& cmd, const QString& args)
{
KConfigGroupSaver gs (KGlobal::config(), "General");
@@ -335,10 +343,9 @@
if (terminal.endsWith("konsole"))
terminal += " --noclose";
- if( args.isEmpty() )
- terminal += QString(" -e /bin/sh -c \"%1\"").arg(cmd);
- else
- terminal += QString(" -e /bin/sh -c \"%1 %2\"").arg(cmd).arg(args);
+ QString qcmd(cmd);
+ if ( !args.isEmpty() ) qcmd += QString(" ")+args;
+ terminal += QString(" -e %1 -c %2").arg(getShell()).arg(KProcess::quote(qcmd));
if (!m_terminalAppList.contains(cmd))
m_terminalAppList << cmd;
@@ -841,7 +848,7 @@
QString Minicli::calculate(const QString &exp)
{
QString result;
- QString cmd = QString("echo $[%1]").arg(exp);
+ QString cmd = QString("%1 -c %2").arg(getShell()).arg(KProcess::quote(QString("echo $[%2]").arg(exp)));
FILE *fs = popen(QFile::encodeName(cmd).data(), "r");
if (fs)
{
------------------------------------------------------
--
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
More information about the kde-core-devel
mailing list