Search code examples
bashglob

Use tab completion in bash script


I have several directories like 1-aaa/ 2-bbb/ 3-cde/. There is only one directory for each number, so echo "test" > 1<TAB>/test is easy. I want to do

for i in 1 2 3
do
    echo "test" > $i-(what to put here?)/test
done

What should I do? Thanks.


Solution

  • The solution with asterisk, like @banderlog013 proposed in comments, doesn't work directly.

    I'm sure that it's possible to find some work-around to use asterisk-solution, but nevertheless you could use some additional step to find the directory :

    #!/bin/bash
    
    for i in 1 2 3
    do
        dir_name=$( find . -type d -name "$i-*" )
        echo "test" > $dir_name/test
    done