bash - What's the meaning of these shell scripts? -


can explain me what's meaning of these shell scripts?

# ......... tmpfile=`tmpfile 2>/dev/null` || tmpfile=/tmp/test$$ trap "rm -f $tmpfile" 0 1 2 5 15 # ......... 

and also, following two, 1 better?

tmpfile=`tmpfile 2>/dev/null` tmpfile=$(tmpfile 2>/dev/null) 

i use trap command , || operator, have looked manual, still have no idea.

this line creates temporary file. if tmpfile fails, errorlevel code passed subshell in subshell forwards calling shell. if code nonzero, default file /tmp/test$$ used instead (|| tmpfile=/tmp/test$$). $$ process id number of shell holds it.

tmpfile=`tmpfile 2>/dev/null` || tmpfile=/tmp/test$$ 

this 1 creates trap shell calls rm -f $tmpfile when signals 0, 1, 2, 5 , 15 received. see kill -l list.

trap "rm -f $tmpfile" 0 1 2 5 15 

using $() on pair of backquotes preferred in posix systems. use on them. $() allows recursion difficult (requires recursive quoting) pair of backquotes.

tmpfile=`tmpfile 2>/dev/null` tmpfile=$(tmpfile 2>/dev/null) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -