QuestionsCategory: BIOSTARwhat does -f stand for in the bash profile setup?
yangz13@nih.gov asked 6 months ago

Hi. Could you please help to explain what is the meaning of [-f ~/.bashrc] in the bashprofile setup below? Thanks

#
if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

Question Tags:
1 Answers
Best Answer
tillodc@nih.gov Staff answered 6 months ago

The  “[ -f ~/.bashrc]” is known as a test command in bash. This command, which includes the “-f” expression,  will check if the ~/.bashrc file exists  (i.e. the file .bashrc is in your home directory) and is a regular file (i.e. is not a directory).

If the expression [ -f ~/.bashrc] is true, then the program will run the  “source ~/.bashrc” command.

For info on other bash expressions http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html