taychive Posted February 18, 2019 Share Posted February 18, 2019 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? Quote Link to comment
Squid Posted February 18, 2019 Share Posted February 18, 2019 ABCabc = Regular sort (ie: ascii values) AaBbCc = Natural sort Quote Link to comment
taychive Posted February 19, 2019 Author Share Posted February 19, 2019 (edited) 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, 2019 by taychive Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.