LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 01:49 PM   #1
DBabo
Member
 
Registered: Feb 2003
Distribution: Scientific Linux 6
Posts: 386

Rep: Reputation: 33
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 01:58 PM.
 
Old 11-21-2012, 02: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 02:13 PM.
 
1 members found this post helpful.
Old 11-21-2012, 02: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, 02:17 PM   #4
DBabo
Member
 
Registered: Feb 2003
Distribution: Scientific Linux 6
Posts: 386

Original Poster
Rep: Reputation: 33
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, 02:18 PM   #5
DBabo
Member
 
Registered: Feb 2003
Distribution: Scientific Linux 6
Posts: 386

Original Poster
Rep: Reputation: 33
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 02:23 PM.
 
  


Reply

Tags
shell scripting


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 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 03:48 PM
shell alias problem raowl Linux - General 2 09-19-2007 11:39 AM
alias with cd in shell mtdew3q Linux - Newbie 6 05-11-2006 04:56 PM
Alias or shell script to confirm 'exit' commands from a shell rose_bud4201 Programming 2 03-08-2006 03:34 PM
alias in bash shell wincrk Linux - General 12 07-20-2004 01:35 PM


All times are GMT -5. The time now is 06:36 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration