Re: Bash scripting problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jan 08, 2005 at 05:41:11PM +0100, Alexander Dalloz wrote:
> Am Sa, den 08.01.2005 schrieb Chadley Wilson um 17:29:
> 
> > I have this issue:

> > in /root/.bashrc there is an alias which breaks my script in the following 
> > way:
> > When I need to copy or del a file the rm -i and cp -i are preventing things 
> > from running smoothly.
> > 
> > I have tried numerous tricks none work?
> > 
> > could some-one please show me how you work around this without editing the 
> > basrc files?
> 
> unalias cp
> 
> at top of your script.

Get them all! (unalias -a) aliases make scripts non portable and hard
to debug as you found.

       unalias [-a] [name ...]
              Remove each name from the list of defined aliases.  If
              -a is supplied, all alias definitions are removed.  The
              return value is true unless a supplied name is not a
              defined alias.

Since this is a script in /root/ I assume it is running more often as
root than not.  Thus, a better solution in this case might be

  CP=/bin/cp
  $CP /tmp/a /tmp/b

This lets you use the safer $CP in your script.  The advantage is that
trojan programs/ scripts that might be hidden in $PATH will not be
found.  This is very important for systems where a person might "su"
in contrast to "su - ".  i.e. The first ("su") does not tidy up $PATH
and bad things might happen.  Since this is in /root the script should
also be setting $PATH and not depending on it.

Do compare and contrast CP=/bin/cp and CP="/bin/cp "!

Other scripts (application drivers) often depend on the users $PATH
so full path names are the most common solution.

For completeness \cp also works to squash the alias.


-- 
	T o m  M i t c h e l l 
	spam unwanted email.
	SPAM, good eats, and a trademark of  Hormel Foods.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux