Skip to content
Advertisement

how to auto complete files names on bash script?

I have a bash shell script that cd to directory according to a variable. After that I press Tab and files don’t appear like in terminal. Ex:

#!bin/bash
clear
mypath=/opt/projects/
cd $mypath
echo "Enter tour file:"
read n
echo $n

on read code ups, the files don’t appear when I press tab.

Advertisement

Answer

The read command requires the -e flag in order to use the readline library to edit the command line (including completions):

echo "Enter tour file: "
read -e n
echo "$n"
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement