AIX中的cut命令补码不起作用

问题描述

我的bash脚本中有一个CUT命令

cut --complement -c 1-5 file.txt > tmp

此命令可在除AIX之外的所有unix环境中使用

如果我在AIX中执行命令,则会收到以下错误

cut: Not a recognized flag: -
Usage: cut -b List [-n] [File...]
   or: cut -c List [File...]
   or: cut -f List [-d Character] [-s] [File...]
 cut: Not a recognized flag: -
bash: cut:: command not found

我拥有的shell脚本将获得范围,例如1-5,这是需要修剪的范围,可以是任何范围。

解决方法

正确。 AIX cut没有该选项(这是GNU extension)。

GNU / Linux用户空间有了很大的发展,而AIX则没有那么大。但是,即使AIX cut所提供的功能也超过required by POSIX。如果要使脚本具有可移植性,则必须找到最小的公分母……或在AIX上安装所需的GNU / Linux用户空间部分。 AIX Toolbox for Linux Applications提供了软件包的集合。 (cut是coreutils的一部分。)