0
0
Linux CLIscripting~20 mins

.bashrc and .bash_profile in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Bash Startup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this command sequence?
You have a .bash_profile that contains echo "Profile loaded" and a .bashrc that contains echo "RC loaded". You start a new login shell. What will be printed?
A
Profile loaded
RC loaded
B
RC loaded
Profile loaded
CProfile loaded
DRC loaded
Attempts:
2 left
💡 Hint
Remember that login shells read .bash_profile and interactive shells read .bashrc.
🧠 Conceptual
intermediate
1:30remaining
Which file is read by a non-login interactive shell?
When you open a new terminal window in a graphical environment (like GNOME Terminal), which file does bash read?
A~/.bash_logout
B~/.bash_profile
C~/.profile
D~/.bashrc
Attempts:
2 left
💡 Hint
Non-login interactive shells read a different file than login shells.
🔧 Debug
advanced
2:00remaining
Why does a command in .bashrc not run on login?
You added echo "Hello from .bashrc" to your ~/.bashrc but it does not print when you login via SSH. Why?
ABecause .bashrc has wrong permissions
BBecause echo commands are ignored in .bashrc
CBecause .bashrc is not read by login shells by default
DBecause SSH disables all shell startup files
Attempts:
2 left
💡 Hint
Think about which files login shells read.
🚀 Application
advanced
2:30remaining
How to ensure .bashrc runs on login shells?
You want your .bashrc commands to run every time you login (including SSH). Which snippet should you add to your ~/.bash_profile?
Aexec ~/.bashrc
B
if [ -f ~/.bashrc ]; then
  source ~/.bashrc
fi
Csource ~/.bash_profile
Dcat ~/.bashrc
Attempts:
2 left
💡 Hint
You want to run .bashrc only if it exists.
💻 Command Output
expert
2:00remaining
What is the output of this .bash_profile snippet?
Given this ~/.bash_profile content:
echo "Start"
if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi
echo "End"
And ~/.bashrc contains:
echo "Inside RC"
What is printed when you login?
A
Start
Inside RC
End
B
Inside RC
Start
End
C
End
Start
Inside RC
D
Start
End
Attempts:
2 left
💡 Hint
Commands run in order as the shell reads the files.