Bash脚本在循环后终止

时间:2019-11-25 18:04:14

标签: bash loops getopts

我正在bash中试用set -e ... package_version="v1.1.0" grafana_username="" grafana_password="" subcommand=$1; shift while [ ! -z "$subcommand" ]; do case "$subcommand" in package_version) package_version=$1; shift; echo "Package_version:::: $package_version" shift $((OPTIND -1)) ;; grafana_username) grafana_username=$1; shift; echo "Grafana_username::: $grafana_username" shift $((OPTIND -1)) ;; grafana_password) grafana_password=$1; shift; echo "Grafana_password::: $grafana_password" shift $((OPTIND -1)); ;; esac subcommand=$1; shift; done touch sample.xml echo "Creating a file" echo "Package version chosen: $package_version" ... 。我添加以下代码段作为示例。

script-setup.sh

$ ./script-setup.sh package_version "v1.3.0" grafana_username "admin" grafana_password "abcd"                                                                                                                                 
Package_version:::: v1.3.0
Grafana_username::: admin
Grafana_password::: abcd
Creating a file
Package version chosen:  v1.3.0

预期结果:

$ ./script-setup.sh package_version "v1.3.0" grafana_username "admin" grafana_password "abcd"                                                                                                                                
Package_version:::: v1.3.0
Grafana_username::: admin
Grafana_password::: abcd

实际结果:

sample.xml

在上述情况下,我们看到:脚本无法创建文件,即。 echo,并且无法执行最后两个loop语句。根据我的说法,这是一种令人困惑的行为,或者也许我是错的。

bash脚本中的for$ bash -version 1 ↵ GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) 循环所代替,但是仍然没有任何改变。

bash版本:

class CreateTablesam extends PureComponent {
  render() {
    const createRow = this.props.tabelDeatils.map(per => (
      <tr key={per.name}>
        <td>{per.name}</td>
        <td>{per.age}</td>
        <td>{per.skill}</td>
      </tr>
    ));

    return (
      <div>
        <table>
          <thead>
            <tr>
              <td>Name</td>
              <td>Age</td>
              <td>skills</td>
            </tr>
          </thead>
          <tbody>{createRow}</tbody>
        </table>
        <button onClick={this.props.addtable}>CLICK</button>
      </div>
    );
   }
  }

0 个答案:

没有答案