我想要Bash 中的if/then语句,但似乎无法使其正常工作。我想说“如果该行以>字符开头,则执行此操作,否则执行其他操作”。
我有:
while IFS= read -r line
do
if [[$line == ">"*]]
then
echo $line'first'
else
echo $line'second'
fi
done
Run Code Online (Sandbox Code Playgroud)
但它不起作用。我还试图通过说来逃避“>”:
if [[$line == ^\>*]]
Run Code Online (Sandbox Code Playgroud)
这也不起作用。我收到此错误的两种方式:
line 27: [[>blah: command not found
Run Code Online (Sandbox Code Playgroud)
建议?
内部需要的空间[[ and ]]如下:
if [[ "$line" == ">"* ]]; then
echo "found"
else
echo "not found"
fi
Run Code Online (Sandbox Code Playgroud)