February 18, 20197 yr Hello, I trying to write a bash script that will generate a report about one of my unraid shares. Inside is a FOR IN loop that points to the shared folder. By default the FOR IN loop searches the directory in ASCII order for example: ( ) 012 ABC [ ] abc { } However, in the WebGui if i browse the disk or shared folder and select ascending by name i get: 012 ( ) [ ] AaBbCc { } I do not know what this type of sorting order is called and couldn't find anything that matched when searching online so this is my first part of my question. What is it called? The second part is how can I write my FOR IN loop to use this order?
February 19, 20197 yr Author Agh it is natural sort, you are right. I read up on it before and thought i understood it, but i was wrong. I thought natural sorting only applies to numbers so a 10 would come after 9 and so on. With that now known, if i add the V and f options to the sort command i can get: 012 AaBbCc ( ) [ ] { } Its closer but still not exactly like the webgui Any idea how to get parentheses and square brackets to come between the numbers and letters? Here is a snippet i was playing around with. #!/bin/bash Folder="Test" oldIFS="$IFS" IFS=$'\n' for Subfolder in `ls -d /mnt/user/"${Folder}"/*/ | sort -t/ -Vf`; do SubfolderSize=$(du -sb "${Subfolder}" | cut -f1) TotalSize=$((TotalSize+SubfolderSize)) DirCount=$((DirCount+1)) echo -n "${Subfolder}" is folder number "${DirCount}" and is" " echo "${SubfolderSize}" | numfmt --to="iec" done IFS="$oldIFS" echo -n "${Folder}" has "${DirCount}" folders and is" " echo "${TotalSize}" | numfmt --to="iec" Edited February 19, 20197 yr by taychive
Archived
This topic is now archived and is closed to further replies.