Re: [blug-prog] Can i know who has issued a comand?
- On 8/29/05, Sumit Chawla <enetra@...> wrote:
>ok, now the shell will be in interactive mode, so you can check for
> I want to put entry in .bashrc for aliasing the rm command.But I want
> that alaising to be conditionnal.The conditions could be:
> 1. Perform alaising only when the "rm" command has been issued by the
> user manually. That is the ussr has typed the command "rm" on the
> $> rm s.txt
interactive mode and call your alias.
2. Skip the alaising otherwise. Say the rm command was inetrnally
> called by some script. say the scaript is:here, the shell will be non-interactive. so, just call normal rm.
> rm s.txt
> I dont want the a;iasing to be done here. Here it should call the
> normal "rm" banary.
as an example, alias 'rm' command to following code snippet:
if [ -z "$PS1" ]; then
#This shell is not interactive
#This shell is interactive
# your choice of commands
so now, when the user types in 'rm -f /', the shell will be in interactive
mode. since rm cmd is now aliased to the shell script, the shell script
detects that it is an interactive shell and does whatever
you wanted to do.
when any shell script is execd (like $ bash <shellscript>), the shell will
be in non-interactive mode. and since rm is aliased, still the script will
be called, but the script detects it is non interactive shell and simply
passes the burden to rm
hope i am clear,
[Non-text portions of this message have been removed]