Command behaves different in script and on prompt

$cat /tmp/tuxob.lst
udi *****
jim 10
ant 19
ibm *****

$ input=`head -1 /tmp/tuxob.lst | awk '{print $NF}'`
$ echo $input

The output I am expecting is ''. But It is showing me the available files of current directory. When I run the command
head -1 /tmp/tuxob.lst | awk '{print $NF}
from unix prompt - I can see the output as '
'

Please advise, what am I doing wrong?

inside your script the variable input will have ****** as value.

and when you echo $input that evaluates to echo ******.

echo * will print the current directories content.

that is what is happening. try to use escape *.

$cat /tmp/tuxob.lst
udi *****
jim 10
ant 19
ibm *****
input=`head -1 /tmp/tuxob.lst | awk '{print $NF}'`

If above is the script, then how do I put if conditions. i.e. If $input = '*****' do something. Because on putting $input displays files of current directory being expanded to echo *

edit by bakunin: i added the CODE-Tags you probably have forgotten.

First off, you don't need any if-contructions. You should quote your variables regardless of them containing something which has to be quoted or not, because even if said variables normally don't have a content which has to be quoted they might do so occasionally and a script shouldn't work "most of the times", but always.

In programming caution sometimes helps but never hurts, so be as cautious as possible.

Secondly, you shouldn't use the backticks any more: they are supported only for backwards compatibility purposes. Use the "$(...)" instead:

input="$(head -1 /tmp/tuxob.lst | awk '{print $NF}')"

Thirdly, the command only fills a variable with some content - in this case some asterisks. No shell expansion is done here. It is probably done when you subsequently try to display the variables contents. THIS is the place where you have to protect your variable from being expanded by the shell:

input="$(head -1 /tmp/tuxob.lst | awk '{print $NF}')"
echo $input         # will be expanded
echo "$input"       # will not be expanded

Btw.: if the only thing you want to do is to display it, you don't even need the variable:

echo "$(head -1 /tmp/tuxob.lst | awk '{print $NF}')"  # will not be expanded
echo $(head -1 /tmp/tuxob.lst | awk '{print $NF}')    # will be expanded

I hope this helps.

bakunin