Reputation: 3512
Please feel free to rename the question to something more appropriate.
How would I mimic the below zsh
using bash
instead?
mkdir folder1
mkdir folder2
mkdir folder3
# zsh
folders=(folder*) | print $folders
#folder1 folder2 folder3
# bash
folders=(folder*/) | echo $folders
#folder1
As you can see, this only outputs the first element.
Any pointers would be appreciated, thanks.
Upvotes: 0
Views: 172
Reputation: 7689
If lets say, you have multiple .txt file in some Directory and you want to get/display those folders . you can try something like this:
declare -a folder_arr
i=0
for dir in *.txt; do
folder_arr[i]=$dir
i=$((i+1))
done
for j in $(seq 0 $((i-1)))
do
echo ${folder_arr[$j]}
done
I excuted the above file and was able to get the expected reult.
/temps$ ./dirrr.sh
z.txt
Upvotes: 0
Reputation: 12715
Try changing it to:
folders=(folder*); echo "${folders[@]}"
folders[@]
gives all the elements in the array${}
expands the output from above command to bash.Upvotes: 4