如何在ksh中对整数数组进行排序Unix Shell脚本 [英] How to sort Integer Array in ksh | Unix Shell Scripting

查看:88
本文介绍了如何在ksh中对整数数组进行排序Unix Shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在KornShell中对整数数组进行排序. 找到了此链接, KornShell整数排序数组,但它似乎无法正常工作并抛出异常错误.

How to sort integer array in KornShell. Found this link, KornShell Sort Array of Integers but it seems to be not working and throwing error.

代码:

NUM_ARR[1]=-1
NUM_ARR[2]=-2
NUM_ARR[3]=-3
NUM_ARR[4]=-4
NUM_ARR[5]=-5
NUM_ARR[6]=-6
NUM_ARR[7]=-7
for file in /home/fimsctl/datafiles/outbound/timelog/timelog_file_*.csv ; do

    SORTED_NUM_ARR=`($(printf "%s\n" ${NUM_ARR[@]} | sort -n))`
 echo ${SORTED_NUM_ARR[*]}
 done

输出:

testb.ksh[118]: -7:  not found

推荐答案

您可以将sort与进程替换一起使用:

You can use sort with process substitution:

sort -n <(printf "%s\n" "${NUM_ARR[@]}")

这篇关于如何在ksh中对整数数组进行排序Unix Shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆