Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Script FOR IN loop does not match webGui sort order

Featured Replies

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? 

ABCabc = Regular sort (ie: ascii values)

AaBbCc = Natural sort

  • 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 by taychive

Archived

This topic is now archived and is closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.