Re: Using aliases or functions in bash script
On Sat, 26 Jan 2008 12:44:42 -0500, Daniel Dickinson wrote:
> ./test.sh
> Line 2 errors out. I imagine the same thing happens with his attempt
> to use his bashrc-defined functions in a script without defining them
> again in the script.
>
> IIUC he wants to know how to use already defined functions/aliases in a
> shell script.
Thanks a thousand Daniel!!! Finally! there is someone who really read my
post and try to understand it before jumping to conclusions.
> A possible way around would be to define the functions in .bashrc and
> then source .bashrc, but I am curious myself as to how one would
> achieve the other (using existing functions rather then defining them
> again in a new script).
Sorry if I was not clear in my OP, to all those people who were trying to
understand what I was saying.
I have the following alias and function *already* defined in my ~/.bashrc:
$ bash
$ alias rd
alias rd='rmdir'
$ type dt
dt is a function
dt ()
{
pushd +$1
}
$ exit
exit
I.e., there are there in the interactive shell. Now I want to use them in
my script:
$ bash -O expand_aliases -c '. ~/.bashrc; (rd /tmp/ttt; alias rd; dt 3; type dt)'
bash: line 0: alias: rd: not found
bash: dt: command not found
bash: line 0: type: dt: not found
I.e., even sourcing .bashrc won't work.
--
Tong (remove underscore(s) to reply)
http://xpt.sourceforge.net/techdocs/
http://xpt.sourceforge.net/tools/
Reply to: