0
0
Linux CLIscripting~20 mins

Tab completion in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Tab Completion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of pressing Tab twice after typing 'ls /et'?
You type ls /et in a Linux terminal and press the Tab key twice quickly. What will the shell display?
AIt completes the command to 'ls /etc/' automatically
BIt shows an error message 'command not found'
CIt lists all files and directories starting with '/et', such as '/etc/'
DIt clears the current command line
Attempts:
2 left
💡 Hint
Think about how tab completion works when multiple matches exist.
💻 Command Output
intermediate
1:30remaining
What happens when you press Tab after typing a unique command prefix?
You type pyth in a Linux terminal where only the command python3 starts with 'pyth'. What happens when you press Tab once?
AIt deletes the typed text
BNothing happens, you must press Tab twice
CIt shows all commands starting with 'pyth'
DThe command auto-completes to 'python3'
Attempts:
2 left
💡 Hint
Think about how tab completion behaves with only one possible match.
📝 Syntax
advanced
2:00remaining
Which command enables programmable tab completion for a custom script?
You want to add tab completion to your custom script named mytool. Which command correctly loads bash completion for it?
Acomplete -F _mytool_completion mytool
Benable_completion mytool
Ctabcomplete mytool
Dbash_completion mytool
Attempts:
2 left
💡 Hint
Look for the bash built-in command that links a function to completion.
🔧 Debug
advanced
2:00remaining
Why does tab completion not work for your script?
You wrote a bash completion function for your script but pressing Tab does nothing. Which is the most likely cause?
AYou used 'compgen' inside the function
BYou forgot to run 'complete -F function_name script_name'
CYou pressed Tab twice instead of once
DYou named the function starting with an underscore
Attempts:
2 left
💡 Hint
Think about how bash knows which function to call for completion.
🚀 Application
expert
2:30remaining
How to create a tab completion that suggests only files with '.txt' extension?
You want to write a bash completion function that suggests only files ending with '.txt' when pressing Tab after your command. Which snippet correctly generates this list?
ACOMPREPLY=( $(compgen -f -- "$1" | grep '\.txt$') )
BCOMPREPLY=( $(compgen -d -- "$1" | grep '\.txt$') )
CCOMPREPLY=( $(compgen -f -- "$1") )
DCOMPREPLY=( $(compgen -f -- "$1" | grep '\.jpg$') )
Attempts:
2 left
💡 Hint
Use 'compgen -f' to list files and filter by extension.