bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Incorrect manage "*" in test -z


From: Dennis Williamson
Subject: Re: Incorrect manage "*" in test -z
Date: Fri, 17 Apr 2015 05:54:18 -0500



On Thu, Apr 16, 2015 at 6:51 PM, Guillermo Buritica Tobon <gburiticato@gmail.com> wrote:
Hi All.

H have the next bash script code.: 

#!/bin/sh
# Pring OK on empty input, 
# Print input on non-empty input

read INPUT
if [ -z "$INPUT" ]; then
        echo OK
else
        echo $INPUT
        while read INPUT; do
                echo $INPUT
        done
fi


The function read one input and print the input or print "OK" if the input is enpty

Example correct use:

echo "Hello World" | ~/OkIfNoInput.sh
Hello World

echo "" | ~/OkIfNoInput.sh
OK

The ISSUE is when the string Contain "*" the results are very estrange. or "*[space]" 

echo "* Hello World *" |  ~/OkIfNoInput.sh
forensic orbit-gtobon postgresql-2015-04-13_000000.log qt_temp.kn3231 qt_temp.Lh3231 qt_temp.nS3231 qt_temp.T28137 query.html server.log smartgrep_60863524962e4077d558766bf2f79235a373cae448da3e11b384b37e7d2f1ea8 ssh-Mxs2Qb6AhJxc systemd-private-1AfwYz systemd-private-2stQfP systemd-private-2ytw5H systemd-private-3xYsUI systemd-private-44tvlt systemd-private-4FOgxG systemd-private-cfGpBQ systemd-private-d6PHV1 systemd-private-EQaIzh systemd-private-FZx2ad systemd-private-GJzO5O systemd-private-GTYlPD systemd-private-H72F9i systemd-private-I6N6mv systemd-private-isBta7 systemd-private-m70a9b systemd-private-missS7 systemd-private-mPbVbC systemd-private-noY0rf systemd-private-nZbmwS systemd-private-obDFE9 systemd-private-OfXH6S systemd-private-P6I7QK systemd-private-PI2Kf0 systemd-private-Q8dNwo systemd-private-qiMHMr systemd-private-QiOvUZ systemd-private-RO0WgV systemd-private-t2Slaz systemd-private-UH50C8 systemd-private-yJIqqS tt.txt zabbix_server_5662.pinger zabbix_server_5680.pinger Hello World forensic orbit-gtobon postgresql-2015-04-13_000000.log qt_temp.kn3231 qt_temp.Lh3231 qt_temp.nS3231 qt_temp.T28137 query.html server.log smartgrep_60863524962e4077d558766bf2f79235a373cae448da3e11b384b37e7d2f1ea8 ssh-Mxs2Qb6AhJxc systemd-private-1AfwYz systemd-private-2stQfP systemd-private-2ytw5H systemd-private-3xYsUI systemd-private-44tvlt systemd-private-4FOgxG systemd-private-cfGpBQ systemd-private-d6PHV1 systemd-private-EQaIzh systemd-private-FZx2ad systemd-private-GJzO5O systemd-private-GTYlPD systemd-private-H72F9i systemd-private-I6N6mv systemd-private-isBta7 systemd-private-m70a9b systemd-private-missS7 systemd-private-mPbVbC systemd-private-noY0rf systemd-private-nZbmwS systemd-private-obDFE9 systemd-private-OfXH6S systemd-private-P6I7QK systemd-private-PI2Kf0 systemd-private-Q8dNwo systemd-private-qiMHMr systemd-private-QiOvUZ systemd-private-RO0WgV systemd-private-t2Slaz systemd-private-UH50C8 systemd-private-yJIqqS tt.txt zabbix_server_5662.pinger zabbix_server_5680.pinger


echo "*" |  ~/OkIfNoInput.sh
forensic orbit-gtobon postgresql-2015-04-13_000000.log qt_temp.kn3231 qt_temp.Lh3231 qt_temp.nS3231 qt_temp.T28137 query.html server.log smartgrep_60863524962e4077d558766bf2f79235a373cae448da3e11b384b37e7d2f1ea8 ssh-Mxs2Qb6AhJxc systemd-private-1AfwYz systemd-private-2stQfP systemd-private-2ytw5H systemd-private-3xYsUI systemd-private-44tvlt systemd-private-4FOgxG systemd-private-cfGpBQ systemd-private-d6PHV1 systemd-private-EQaIzh systemd-private-FZx2ad systemd-private-GJzO5O systemd-private-GTYlPD systemd-private-H72F9i systemd-private-I6N6mv systemd-private-isBta7 systemd-private-m70a9b systemd-private-missS7 systemd-private-mPbVbC systemd-private-noY0rf systemd-private-nZbmwS systemd-private-obDFE9 systemd-private-OfXH6S systemd-private-P6I7QK systemd-private-PI2Kf0 systemd-private-Q8dNwo systemd-private-qiMHMr systemd-private-QiOvUZ systemd-private-RO0WgV systemd-private-t2Slaz systemd-private-UH50C8 systemd-private-yJIqqS tt.txt zabbix_server_5662.pinger zabbix_server_5679.pinger



This is an expected result?
I'm doing something wrong?
Or is this a bug in bash?



Kind Regards


Guillermo Buritica T.

Always quote your variables. The problem comes from

echo $INPUT

which should be

echo $INPUT

--
Visit serverfault.com to get your system administration questions answered.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]