I am a beginner to the unix scripts, can anyone please explain what does the below lines mean:


rm $BTEQTEMPDELLOGS 2>/dev/null 1>/dev/null
  • 2
    I'm curious about the reasons of downvoting. I'm not saying the question doesn't necessarily deserve it, but I think for a newbie proper feedback is helpful. – schrodigerscatcuriosity Aug 8 '19 at 17:48
  • 3
    I suspect the downvote is for "This question does not show any research effort ..." – roaima Aug 8 '19 at 18:34
  • sorry evryone .its been few days i started researching , but i was not knowing about /dev/null .so thought of posting it – chetan gowda Aug 9 '19 at 7:30
  • @chetangowda It becomes quite a different question if you had said it was /dev/null that was your issue, and not the rm or the variable assignment or something else. – Kusalananda Aug 9 '19 at 8:21
  • In the crontab-related duplicate, look in particular at the answer from the user called Sree – Kusalananda Aug 9 '19 at 8:34

The rm ("remove") command removes a file. The name of the file to be removed is given in a variable BTEQTEMPDELLOGS, instead of directly. Any error messages (2>) by rm are sent to /dev/null (thrown away), the same for normal output (1>).

The variable BTEQTEMPDELLOGS itself is constructed in your first line by concatinating the variable LOGS, a literal '/' and the variable tablename with the string ".DELlog" at the end.

Here is documentation on (input and) output redirection: GNU bash manual: Redirections.

In your example, only output is redirected, not input. 1> redirects the normal messages issued by rm (there usually are none), 2> redirects only the error messages (file not found etc.).

Here is more detailed information on these numbers ("file handles" from the programmer's point of view): stdin (0), stdout (1) and stderr (2) in-/output of programs.

Here is documentation on /dev/null: Wikipedia: NULL device

  • 1
    Additionally, since the $BTEQTEMPDELLOGS value is used unquoted, it will be split on whitespaces (spaces, tabs and newline by default) and each generated word will undergo filename globbing if they contain filename globbing characters (such as * or [ or ?, or backslash (in recent versions of bash)) before rm is called to delete the file corresponding to each word. – Kusalananda Aug 8 '19 at 17:39
  • Yes, an improvement of the code would be to use rm "$BTEQTEMPDELLOGS" 2>/dev/null 1>/dev/null. – Ned64 Aug 8 '19 at 17:40
  • 1
    Or just rm -- "$BTEQTEMPDELLOGS" 2>/dev/null, as rm never generates output, and you'd want to protect the value from being interpreted as a set of options, just in case it ($LOGS really) starts with a dash. – Kusalananda Aug 8 '19 at 17:41
  • @Kusalananda The variable seems to created by ourselves (lines above the snippet), not user input, so this might well be only a theoretical risk and may complicate discussion. – Ned64 Aug 8 '19 at 17:44
  • Possibly, but we don't actually know where $LOGS comes from. – Kusalananda Aug 8 '19 at 17:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.