LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-21-2012, 12:49 PM   #1
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Rep: Reputation: 40
shell redefine the command akak alias


a quick question for bash guru:

how to redefine the built in command without in the script?

example:
Code:
#!/bin/ksh

echo=$(echo -e)
echo "\t Doesn't work"
the desired result is to be able to use "echo -e" every time i type "echo" in the script.
I do NOT want to specify alias in the .rc just want to have it local to the script.
Thank you
AZ

Last edited by DBabo; 11-21-2012 at 12:58 PM.
 
Old 11-21-2012, 01:11 PM   #2
oliverg
LQ Newbie
 
Registered: Nov 2012
Posts: 3

Rep: Reputation: Disabled
have you tried

Code:
alias echo = 'echo -e'

rest of script
...
..
.
cd
. .bashrc
i believe this should set the alias then restore your original shell when you finish!!

hope i helped

Edit: Oops just realised your using ksh. well thats how i think youd do it in bash, translate that to ksh you should be good

Last edited by oliverg; 11-21-2012 at 01:13 PM.
 
1 members found this post helpful.
Old 11-21-2012, 01:16 PM   #3
VDP76
Member
 
Registered: Apr 2010
Location: Bayreuth, Germany
Distribution: CrunchBang Linux (#!)
Posts: 111

Rep: Reputation: 19
hi,

I am no bash guru and maybe you have already tried this, but I'll give it a try...does the following command, written at the beginning of your script, do the trick!?
Code:
alias echo='echo -e'
 
1 members found this post helpful.
Old 11-21-2012, 01:17 PM   #4
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by oliverg View Post
have you tried

Code:
alias echo = 'echo -e'

rest of script
...
..
.
cd
. .bashrc
i believe this should set the alias then restore your original shell when you finish!!

hope i helped

Edit: Oops just realised your using ksh. well thats how i think youd do it in bash, translate that to ksh you should be good
Thank you. But it's a pain to re-run rc just to get rid of echo -e.
 
Old 11-21-2012, 01:18 PM   #5
DBabo
Member
 
Registered: Feb 2003
Distribution: Fedora {latest}
Posts: 568

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by VDP76 View Post
hi,

I am no bash guru and maybe you have already tried this, but I'll give it a try...does the following command, written at the beginning of your script, do the trick!?
Code:
alias echo='echo -e'
Thank you - i tried that - no luck.
I should be explicit tho:
it works in the sense it defines the "echo -e", BUT "echo -e" remains defined after script ends.

ahh. And moment of truth was right there in front of my fingers. Here is the current solution:

Code:
#!/bin/ksh
alias echo='echo -e '

<blah>
unalias echo
# EOF
Thank you!

Last edited by DBabo; 11-21-2012 at 01:23 PM.
 
  


Reply

Tags
shell scripting



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: command works at command line, but not via an alias porphyry5 Programming 3 03-17-2012 02:48 PM
shell alias problem raowl Linux - General 2 09-19-2007 10:39 AM
alias with cd in shell mtdew3q Linux - Newbie 6 05-11-2006 03:56 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 02:34 PM
alias in bash shell wincrk Linux - General 12 07-20-2004 12:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:04 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
Open Source Consulting | Domain Registration