0

I must find a non-trivial approach for a trivial printf "%s". In my case all keywords are a physical files in different locations. I would like to be able using a tab button to complete locations/files just as with CLI, and display all the files if they start with the same letters. Is it possible to add the index of the system to a bash script? Eg:

#!/bin/bash

printf "%s" "The file is: "
read keyword

~~~~~~~~~

./script.sh
The file is: /home/user/file
(Hit tab)
file.txt file2 file5
/home/user/file.
(Hit tab)
/home/user/file.txt

The files can be in different locations. Only 1 parameter will be provided at once.

faceless
  • 450
  • 4
  • 15

1 Answers1

1

printf isn't relevant here; it's read for which you want completion. In bash, enable Readline support with the -e option.

read -e keyword

You can do away with the printf command altogether, by the way, by using the -p option to print the prompt:

read -p "The file is: " -e keyword
chepner
  • 497,756
  • 71
  • 530
  • 681