I am a beginner to the unix scripts, can anyone please explain what does the below lines mean:
BTEQTEMPDELLOGS=$LOGS/${tablename}.DELlog
rm $BTEQTEMPDELLOGS 2>/dev/null 1>/dev/null
I am a beginner to the unix scripts, can anyone please explain what does the below lines mean:
BTEQTEMPDELLOGS=$LOGS/${tablename}.DELlog
rm $BTEQTEMPDELLOGS 2>/dev/null 1>/dev/null
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
$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 08 '19 at 17:39
rm "$BTEQTEMPDELLOGS" 2>/dev/null 1>/dev/null
.
– Ned64
Aug 08 '19 at 17:40
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 08 '19 at 17:41
rm
command usually has no input (except when used interactively, e.g. rm -i .......
). I am adding more information on the distinction between 1>
and 2>
). If it helped please accept the answer.
– Ned64
Aug 09 '19 at 07:59
/dev/null
that was your issue, and not therm
or the variable assignment or something else. – Kusalananda Aug 09 '19 at 08:21