Loading ...
Sorry, an error occurred while loading the content.

Re: [blug-prog] Can i know who has issued a comand?

Expand Messages
  • Venkatesan S
    ... ok, now the shell will be in interactive mode, so you can check for interactive mode and call your alias. 2. Skip the alaising otherwise. Say the rm
    Message 1 of 5 , Aug 29, 2005
    • 0 Attachment
      On 8/29/05, Sumit Chawla <enetra@...> wrote:
      >
      > 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
      > Prompt.
      >
      >
      > $> rm s.txt


      ok, now the shell will be in interactive mode, so you can check for
      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:
      > *********************
      > #sum.sh
      > rm s.txt
      > ****************
      >
      > I dont want the a;iasing to be done here. Here it should call the
      > normal "rm" banary.
      >
      here, the shell will be non-interactive. so, just call normal rm.
      as an example, alias 'rm' command to following code snippet:

      if [ -z "$PS1" ]; then
      #This shell is not interactive
      /bin/rm $*
      else
      #This shell is interactive
      # your choice of commands
      fi

      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,
      Venkatesan


      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.