Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   Problem with aliasing (http://www.programmingforums.org/showthread.php?t=7697)

a thing Dec 23rd, 2005 6:55 PM

Problem with aliasing
 
I'm using kdialog a lot in a Bash script, and I always use the option --title="$title". So I made an alias, alias kdialog="kdialog --title=\"$title\"". The line alias|grep kdialog in the script outputs alias kdialog='kdialog --title="Audio Konvert 0.3.0"', but the title of a dialog created with kdialog --yesno "test" has a title of "Question - KDialog."

I'm trying to keep this all in one script.

a thing Dec 26th, 2005 8:56 PM

Anyone?

Arevos Dec 27th, 2005 4:15 AM

Funny; it works for me. What version of KDE are you using?

a thing Dec 27th, 2005 8:37 AM

notroot[0:~]& rpm -q kdebase
kdebase-3.5.0-0.1.fc4
notroot[0:~]&

Mabe it's something wrong with somethinge else in the script...? Should I attach it (It's 37KB)?

Arevos Dec 27th, 2005 10:38 AM

Same KDE version I have, so it's nothing to do with 3.5. Have you tried doing this normally?
:

title="Audio Konvert 0.3.0"
alias kdialog="kdialog --title=\"$title\""
kdialog --yesno "Testing, 1, 2, 3."


a thing Dec 27th, 2005 10:50 AM

Now try putting that in a shell script.

Arevos Dec 27th, 2005 1:06 PM

Quote:

Originally Posted by a thing
Now try putting that in a shell script.

Ah. I see what you mean. Curious indeed. Perhaps aliases are meant only for interactive use?

Perhaps use a function instead?
:

function kdialog
{
    /usr/bin/kdialog --title="$title" $*
}

I've put in the full path of kdialog in the function, because otherwise the function will recursively call itself.

Functions will only be around for the duration of the script, I believe (unless you put them in bashrc or similar), but they are called the same way you would call a regular command or alias:
:

kdialog --yesno "Testing, 1, 2, 3."

aznluvsmc Dec 27th, 2005 9:52 PM

Aliases are disabled for non-interactive shells (shell scripts) according to my book so I guess your experiment confirms it.

a thing Dec 27th, 2005 11:07 PM

Good idea Arevos :)
:

#!/bin/bash
title="This is a test."
kdialog ()
{
        `kde-config --prefix`/bin/kdialog --title="$title $* #or $@
}
kdialog --yesno "Testing, 1, 2, 3."


almost works. The title works, but the content is "Testing," and excludes " 1, 2, 3."

Arevos Dec 28th, 2005 3:42 AM

:

`kde-config --prefix`/bin/kdialog --title="$title $* #or $@
Aren't you missing a " after $title? Could that be what's wrong with it?


All times are GMT -5. The time now is 1:59 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC