# How to check if previous shell task returns an empty string

**URL:** <https://forum.ansible.com/t/how-to-check-if-previous-shell-task-returns-an-empty-string/18836>\
**Category:** Ansible Project\
**Created:** [July 23, 2015, 7:18pm UTC](https://forum.ansible.com/t/how-to-check-if-previous-shell-task-returns-an-empty-string/18836 "2015-07-23T19:18:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dump\_Hole](https://avatars.discourse-cdn.com/v4/letter/d/bbe5ce/32.png) [@Dump\_Hole](https://forum.ansible.com/u/Dump_Hole)\
**Post date:** [July 23, 2015, 7:18pm UTC](https://forum.ansible.com/t/how-to-check-if-previous-shell-task-returns-an-empty-string/18836/1 "2015-07-23T19:18:12Z")

</div>

I have two shell tasks. The first one runs a check and returns a list of ids to be removed. The second one will remove these ids.

The stdout of the first task looks like this:  
1  
2  
3  
4

which then gets fed into the second task to remove 1, 2, 3, 4

But if the first one cannot find ids to be removed, it will instead return an empty string rather than an error. How do I check in Ansible for an empty string, and how do I pass I set the variable through register

- name: task1  
shell: script1  
register: result
- name: task2  
shell: script2 `script1`  
when: result.length() \> 0 \<\<\< ??

I tried with stdout\_lines.length(), length, size(), size, len(). No luck.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 23, 2015, 7:42pm UTC](https://forum.ansible.com/t/how-to-check-if-previous-shell-task-returns-an-empty-string/18836/2 "2015-07-23T19:42:02Z")

</div>

i think you want:  
&nbsp;&nbsp;result.stdout|length \> 0
