I have the following bash script that should list the folders in the same directory, and let me choose a folder to move in, and then list its content.
select dest in $( command ls -aF | grep "/" ); do
if [ -d $dest ]; then
echo "$0 : changed to $dest"
echo "$0 : wrong choice" 1>$2
1/ 2/ 3/ 4/ 5/ select.sh
dest= [ -d $dest ]
What does this do? It runs the command:
[ -d ]
What does that do? It's shorthand for:
[ -n "-d" ]
...which is to say, it checks whether
-d is empty, which it isn't, so the result is true.
Use More Quotes
Consider this instead:
dest="" [ -d "$dest" ]
When run, it doesn't invoke
[ -d ]; instead, it runs
[ -d '' ]: The quotes prevented the expansion results from being split into a different number of strings than they started as.
When On Bash, Consider The Extended Test Form
[[ -d $dest ]]
...suppresses string-splitting and glob expansion, so it works even without quotes.