bashglob

Bash script drops spaces upon assignment


Here is the script:

#!/bin/bash

faixa_num=90
select_dir="A"
full_path="/home/mel/smbshare/PassporteParaPortuguese/LIDEL*"
full_path="$full_path"$select_dir/

find $full_path -type f -name $faixa_num*.ogg

glob_full_path=$(find $full_path -type f -name $faixa_num*.ogg)
echo $glob_full_path

It simply does a find and then stores the result of the find to variable which is then echoed. They should be the same. But here is what I see on the terminal: Notice the echo is missing 2 spaces.

Please advise. Why are the spaces missing?


Solution

  • echo never sees the spaces. You could do a

    echo "$glob_full_path"
    

    which would work for you concrete case, but this could break, if your path contains backslash characters. To catch this case, I suggest to do

    printf "%s\n" "$glob_full_path"