Shell script to read variables from file and use that in perl script

时间:2017-12-18 07:39:20

标签: bash shell

I want to write a shell script, that reads a file and use the columns of that file as input for a perl script. The perl script is going through files (number1, number2), pulls out the ID and write those to a new file. The perl script is working fine if I use it with the command line, however, my question is how I write a shell script to use the variables in my input_file for the perl script.

My input_file looks like

<views:YourUserControlName Test="{Binding SomeViewModel.SomeTextProperty}"/>
<views:YourUserControlName Test="{Binding SomeOtherViewModel.SomeTextProperty}"/>

And I use the following shell script (which is not working, so please help with this)

number1 ID1
number2 ID2

1 个答案:

答案 0 :(得分:2)

Replace

 ERROR! Unexpected Exception: dictionary update sequence element #0 has length 1; 2 is required
    the full traceback was:

    Traceback (most recent call last):
      File "/usr/bin/ansible", line 92, in <module>
        exit_code = cli.run()
      File "/usr/lib/python2.6/site-packages/ansible/cli/adhoc.py", line 129, in run
        inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory)
      File "/usr/lib/python2.6/site-packages/ansible/inventory/__init__.py", line 92, in __init__
        self.parse_inventory(host_list)
      File "/usr/lib/python2.6/site-packages/ansible/inventory/__init__.py", line 159, in parse_inventory
        group.vars = combine_vars(group.vars, self.get_group_variables(group.name))
      File "/usr/lib/python2.6/site-packages/ansible/inventory/__init__.py", line 527, in get_group_variables
        self._vars_per_group[groupname] = self._get_group_variables(groupname, vault_password=vault_password)
      File "/usr/lib/python2.6/site-packages/ansible/inventory/__init__.py", line 545, in _get_group_variables
        vars = combine_vars(vars, self.get_group_vars(group))
      File "/usr/lib/python2.6/site-packages/ansible/inventory/__init__.py", line 727, in get_group_vars
        return self._get_hostgroup_vars(host=None, group=group, new_pb_basedir=new_pb_basedir, return_results=return_results)
      File "/usr/lib/python2.6/site-packages/ansible/inventory/__init__.py", line 788, in _get_hostgroup_vars
        host_results = self._variable_manager.add_group_vars_file(base_path, self._loader)
      File "/usr/lib/python2.6/site-packages/ansible/vars/__init__.py", line 616, in add_group_vars_file
        data = self._load_inventory_file(path, loader)
      File "/usr/lib/python2.6/site-packages/ansible/vars/__init__.py", line 574, in _load_inventory_file
        rval.update(data)
    ValueError: dictionary update sequence element #0 has length 1; 2 is required

with

$number_ID.ext

${number}_ID.ext is a character allowed in variable names. That's why bash is looking for _. $number_ID is not allowed.