Monday, 20 March 2023

linux/unix interview questions

 1. difference single quote, double quote, back tick

  • single quote: preserve literal value
  • double quote: variable expansion and command substitution
  • back tick: command substitution

2. difference between >, >>, 2>
  • >: redirect stdout to file and overwrite
  • >>: redirect stdout to file and append
  • 2>: redirect stderr to file and overwrite

3. command1 & command2 & wait
  • wait for concurrent and background running commands to finish

4. trap 'rm -f /tmp/tempfile' EXIT
  • do cleanup when script exit normal/abnormally
  • put this line at beginning of script

5. difference source vs exec a script
  • source execute in current shell, afterwards variable and function remains
  • exec create subshell to execute, afterwards nothing left

6. difference test, [], [[]]
  • test and [] are the same 
  • [[]] is better

No comments:

Post a Comment