Advertisements
I write a function like this to .commands
file, and I imported .commands
in .zshrc
function testA() {
echo "start"
if [ "$1" == "a" ]; then
echo "ok"
fi
echo "end"
}
And when I run testA a
in terminal
start
testA:2: = not found
What is the problem here?
>Solution :
Chapter 12 – "Conditional Expressions" of the zsh
documentation states:
A conditional expression is used with the
[[
compound command to test attributes of files and to compare strings.
This means, changing your conditional expression to use [[ ... ]]
instead of [ ... ]
should make it work:
function testA() {
echo "start"
if [[ "$1" == "a" ]]; then
echo "ok"
fi
echo "end"
}