Using cygwin bash on Windows XP. Bash version: 4.3.46(7)-release. Minimal working example, sorting an array in reversed order:
#!/bin/bash
array=("a c" b f "3 5")
IFS=$'\r\n' sorted=($(sort -r <<<"${array[*]}"))
printf "[%s]\n" "${sorted[@]}"
Error in cygwin:
-rThe system cannot find the file specified.
On Linux works fine. The error is caused by -r
flag. How to fix?
Seems like your version of sort
does not support the -r
flag. You could ...
man sort
for an equivalent option.tac
(the reverse of cat
), or if that isn't available perl -e 'print reverse <>'
.sort -r <<< "string"
use sort <<< "string" | tac
.Please also have a look at Glenn Jackman's Answer regarding possible problems in your script.