简体   繁体   English

linux 内置读取命令标志

[英]linux built-in read command flags

I am running into an odd situation.我遇到了一个奇怪的情况。 I am on RHEL 6.3.我在 RHEL 6.3 上。 I am trying to use the built-in 'read' command to read the lines in the file in an array and to process it.我正在尝试使用内置的“读取”命令读取数组中文件中的行并对其进行处理。

In my script, I am using在我的脚本中,我使用

while IFS=" " read -r -a appInfo
do
    echo "4 ${appInfo[0]}"
    echo "4 ${appInfo[1]}"
    echo "4 ${appInfo[2]}"
    echo "4 line *{appInfo[@]}"
    currentApp="${appInfo[*]}"
.....
done < details.txt

It is working fine, when I execute the script from the command line.当我从命令行执行脚本时,它工作正常。 The read command shows the below info读取命令显示以下信息

read: usage: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]

If I do read --version on command line, I get如果我在命令行上read --version ,我会得到

Commandline version read (AT&T Research) 2006-12-19命令行版本读取 (AT&T Research) 2006-12-19

But when I try to execute the exact same script from a Bamboo project, the read command generates an error但是当我尝试从 Bamboo 项目执行完全相同的脚本时,读取命令会生成错误

read: -a: unknown option
Usage: read [-ACprsv] [-d delim] [-u fd] [-t timeout] [-n nchar] [-N nchar]
            [var?prompt] [var ...]

Bamboo : version read (AT&T Research) 2006-12-19 Bamboo :版本阅读 (AT&T Research) 2006-12-19

So, if the version shows the same, why do the flags show differently?那么,如果版本显示相同,为什么标志显示不同?

What could be the problem.可能是什么问题呢。 How can I solve the issue, so that I can read the line into an array even when running it from a Bamboo plan?我该如何解决这个问题,以便即使从 Bamboo 计划中运行它,我也可以将其读入数组?

Thanks to @John1024, I was able to fix the problem by changing the #!感谢@John1024,我能够通过更改 #! line to #!/bin/bash from #!/bin/sh ( which was running the default ksh shell ).从 #!/bin/sh (运行默认的 ksh shell)到 #!/bin/bash 的行。

The credit of solution goes to @John1024, just putting this as an answer so that it can be marked as a solution to question.解决方案的功劳归于@John1024,只是将其作为答案,以便将其标记为问题的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM