Gentoo Archives: gentoo-dev

From: "Pascal J.Bourguignon" <pjb@×××××××××××××.com>
To: gentoo-user@l.g.o
Cc: gentoo-dev@l.g.o
Subject: [gentoo-dev] [gentoo-user] Re: rm tragedies: a modest suggestion
Date: Tue, 01 Jun 2004 18:40:46
Message-Id: 16572.52822.57616.522574@thalassa.informatimago.com
1 Thorsten Kampe writes:
2 > * Todd Berman (2004-05-31 08:39 +0100)
3 > > So when you have been up for 30 hours you are going to remember to type
4 > > -c? cause aliasing will break those same shell scripts...
5 >
6 > Aliases /never/ break scripts.
7 >
8 > > this is a pointless debate in my opinion, especially one to have here
9 > > over a course of days. If you want a safe rm, alias -i and accept
10 > > breakage [...]
11 >
12 > There is nothing to accept even if someone would deny the fact that
13 > shells are primarily built and used for interactive use.
14 >
15 > Scripts are just scripts. They work for me or they don't and if they
16 > don't I fix them. If I would care about this fact then I wouldn't use
17 > a shell script but a real programming language (Python, whatever).
18 >
19 > But let me repeat: aliases don't break scripts.
20
21 That's true IF aliases are defined in the right place.
22
23 Unfortunately, the "rc" files that are automatically executed by bash
24 processes are quite hard to make out, depending on whether the shell
25 is a login shell, an interactive shell or a script.
26
27 >From my reading of bash(1), I reduced it to the following rules (note
28 the OR ELSE clauses that are selected only if no previous clause was
29 selected):
30
31 # WHEN starting
32 # AND ( interactive AND login ) OR ( non-interactive AND --login ) )
33 # DO /etc/profile
34 # THEN ~/.bash_profile
35 # OR ELSE ~/.bash_login
36 # OR ELSE ~/.profile
37 #
38 # WHEN starting
39 # AND interactive AND NOT login
40 # DO ~/.bashrc
41 #
42 # WHEN starting
43 # AND NOT interactive
44 # DO $BASH_ENV
45 #
46 # WHEN exiting
47 # AND login
48 # DO ~/.bash_logout
49
50
51 So, for scripts, it depends on the value of BASH_ENV. You have to put
52 your aliases in a file that is not designed by BASH_ENV nor sourced*
53 by the file designed by BASH_ENV.
54
55 --
56 __Pascal_Bourguignon__ http://www.informatimago.com/
57 There is no worse tyranny than to force a man to pay for what he doesn't
58 want merely because you think it would be good for him.--Robert Heinlein
59 http://www.theadvocates.org/
60
61 --
62 gentoo-dev@g.o mailing list