LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-01-2006, 09:13 AM   #1
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,414
Blog Entries: 1

Rep: Reputation: 65
alias not working as expected


Dear fellows,

I am defining an alias like this:
Code:
$ bash
$ alias test='echo prefix:$1'
$ test string
prefix: string
$
but, the expected output would be "prefix:string".

How to avoid that space after the ":" ?

thanks in advance,
 
Old 06-01-2006, 10:45 AM   #2
exman
LQ Newbie
 
Registered: May 2006
Location: Germany, BS
Distribution: Debian Kernel 2.6.15, Kubuntu Dapper
Posts: 24

Rep: Reputation: 15
Try this one:
Code:
alias test='echo -n prefix:;echo $1'
exman
 
Old 06-01-2006, 01:17 PM   #3
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,414

Original Poster
Blog Entries: 1

Rep: Reputation: 65
Thanks for the try, but your trick is not good. It will work only with echo.

I really need an alias "myalias argument" which is expanded to "command:argument", and what I am getting is "command: argument".

If you have any ideas why that space is inserted by the alias expansion, it will be great.
 
Old 06-01-2006, 01:46 PM   #4
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,414

Original Poster
Blog Entries: 1

Rep: Reputation: 65
solved...

from the bash manual:
Quote:
Originally Posted by man bash, aliases section
If arguments are needed, a shell function should be used (see FUNCTIONS below).
So, the solution is to use functions.

thanks for your time,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
S_ISDIR not working as expected. what is going on? zeppelin Programming 8 04-19-2007 11:21 AM
Useradd - not working as expected Paean Solaris / OpenSolaris 13 01-31-2006 05:06 PM
Crontab not working as expected nro Linux - Newbie 7 08-29-2005 01:56 PM
chmod u+s not working as expected clinton Linux - Newbie 3 03-19-2004 08:49 PM
up2date not working as expected johnny13 Linux - Newbie 7 07-21-2003 02:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration