Bash scripting - request user for input file, how to do work on tab completion?

I am writing a simple bash script where I ask the user to execute an input file.

I am currently using the read -p command. However, it does not work with inline completion for file / directory names on unix. Each time I press Tab during this prompt, my terminal simply skips spaces like the Tab functions in a text editor. Is there any way to enable this?

+8
bash shell
source share
1 answer

Use -e :

 #!/bin/bash read -e -p "Enter filename, use tab for completion: " file ls -l "$file" 

-e uses the readline library to read input in the same way as bash for prompts. This allows you to not only fill out the file name, but also use the arrow keys, home / end, vi editing and similar kindness.

+12
source share

All Articles