How to place a wildcard character in a bash string -
i have directory usr/src/code
and since use different , people can place anywhere in work space want make long src/code available in directory work such */src/code
here have tried , has not worked:
#!/bin/bash directory="/src/code" if [ -d "\*$directory" ]; # enter here if $directory exists, if contains spaces echo "true" fi #!/bin/bash directory="*/src/code" if [ -d "\$directory" ]; # enter here if $directory exists, if contains spaces echo "true" fi #!/bin/bash directory="\*/src/code" if [ -d "\$directory" ]; # enter here if $directory exists, if contains spaces echo "true" fi
globs can match multiple files, it's better store them in array:
#!/bin/bash shopt -s nullglob globstar # enable recursion , 0 matching directories=( **/src/code ) case "${#directories[@]}" in 1) echo "found directory: ${directories[0]}" ;; 0) echo "there no matches..." ;; *) echo "there more 1 match!" ;; esac