[OT] Using aliases or functions in bash script
On Wed, 23 Jan 2008 20:47:15 -0900, Ken Irving wrote:
>> I'm wondering if you have read my OP or not. Read it again pls.
>
> source ~/.bashrc
Guess that I am having bad lucks now, having two people replied without
even reading my question, and the two replies are the only replies that I
get...
Here is the full OP -- let me try for the last time:
Hi,
An advanced bash alias expansion question --
How can I use my aliases or functions in my bash script?
I have the following alias and function defined in my ~/.bashrc:
$ alias rd
alias rd='rmdir'
$ type dt
dt is a function
dt ()
{
pushd +$1
}
How can I use them in my script?
Looking through the man pages, I think the following content is related
to my question:
Aliases are not expanded when the shell is not interactive, unless the
expand_aliases shell option is set using shopt.
[-+]O [shopt_option]
shopt_option is one of the shell options accepted by the
shopt builtin (see SHELL BUILTIN COMMANDS below). If
shopt_option is present, -O sets the value of that option; +O
unsets it. If shopt_option is not supplied, the names and
values of the shell options accepted by shopt are printed on
the standard output. If the invocation option is +O, the
output is displayed in a format that may be reused as input.
expand_aliases
If set, aliases are expanded as described above under
ALIASES. This option is enabled by default for interac-
tive shells.
And this is what I've tried:
$ bash -c 'shopt -s expand_aliases; alias rd'
bash: line 0: alias: rd: not found
$ bash -O expand_aliases -c 'rd /tmp/ttt; alias rd; dt bin; type dt'
bash: rd: command not found
bash: line 0: alias: rd: not found
bash: dt: command not found
bash: line 0: type: dt: not found
Looking for the answer myself, I found a similar symptom has been reported
as bug 148505: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=148505
And it is reported as being fixed.
Am I hitting a new bug or I'm doing something wrong? Please comment,
otherwise I'm going to file a bug report.
Thanks
PS. I even tried the following but it didn't work either:
$ bash -O expand_aliases -c '. ~/.bashrc; (rd /tmp/ttt; alias rd; dt bin; type dt)'
--
Tong (remove underscore(s) to reply)
http://xpt.sourceforge.net/techdocs/
http://xpt.sourceforge.net/tools/
Reply to: