I am trying to use the simple fuinction below. But i get error sayin unary oprator expected and the output is always one
. Can any1 help me correct it.
#!/bin/bash
checkit ()
{
if [ $1 = "none" ]
then
开发者_运维技巧 echo "none"
else
echo "one"
fi
}
checkit
$1
is an argument to the entire script and not to the function checkit()
. So send the same argument to the function too.
#!/bin/bash
checkit ()
{
if [ $1 = "none" ]
then
echo "none"
else
echo "one"
fi
}
checkit $1
This has to work.
Use the [[
keyword instead of the [
builtin:
#!/bin/bash
checkit ()
{
if [[ $1 = none ]]
then
echo none
else
echo one
fi
}
checkit
Please read the Bash pitfalls and the Bash FAQ.
Surround $1
with quotes like this:
#!/bin/bash
checkit ()
{
if [ "$1" = "none" ]
then
echo "none"
else
echo "one"
fi
}
checkit
精彩评论