New answers tagged

1

What you are trying to do is called variable indirection—you want to refer to the variable whose name is stored inside another variable. This is possible in bash—just refer to "${!i}" instead of $i. Also note the importance of double quotes around your variables. That said...you can simplify your script drastically. For instance, here is a one-liner that ...


1

You are looping from 1 to [number of arguments], and then testing if each of those numbers is in fact a directory. It might be simpler to do something like: #!/bin/bash for item in "$@"; do # iterate over the arguments themselves if [[ ! -d "$item" ]]; then echo "$item is not a directory" >> file.txt else DIRECTORY=$(ls -l ...



Top 50 recent answers are included