pangpui
挪威森林的猫
采纳率0%
2018-11-13 01:46

shell中关于IFS和for的奇怪现象

代码如下:

#!/bin/sh

VAL="/aaa/bbb/ccc/ddd//@PLATFORM/eee/fff"

IFS="@PLATFORM"

for var in $VAL
do
echo "$var"
done

结果如下:
~$ sh -x ./test.sh

  • VAL=/aaa/bbb/ccc/ddd/@PLATFORM/eee/fff
  • IFS=@PLATFORM
  • for var in '$VAL'
  • echo /aaa/bbb/ccc/ddd// /aaa/bbb/ccc/ddd/
  • for var in '$VAL'
  • echo ''

  • for var in '$VAL'

  • echo ''

  • for var in '$VAL'

  • echo ''

  • for var in '$VAL'

  • echo ''

  • for var in '$VAL'

  • echo ''

  • for var in '$VAL'

  • echo ''

  • for var in '$VAL'

  • echo ''

  • for var in '$VAL'

  • echo ''

  • for var in '$VAL'

  • echo /eee/fff
    /eee/fff

理论上不应该是只输出/aaa/bbb/ccc/ddd/和/eee/fff两行吗

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

相关推荐