当前位置: 技术问答>linux和unix
初学shell编程遇到的问题,各位大虾进来围观
来源: 互联网 发布时间:2016-09-14
本文导语: 小弟最近初学ubuntu linux下shell编程,遇到如下程序运行出现问题,求高手指点; 源程序如下: #! /bin/bash echo -n "word1:" read word1 echo -n "word2:" read word2 echo -n "word3:" read word3 if [ "$word1" = "$word2" -a "$word2" = "$wor...
小弟最近初学ubuntu linux下shell编程,遇到如下程序运行出现问题,求高手指点;
源程序如下:
#! /bin/bash
echo -n "word1:"
read word1
echo -n "word2:"
read word2
echo -n "word3:"
read word3
if [ "$word1" = "$word2" -a "$word2" = "$word3"]
then
echo "Match:word 1 ,2 ,& 3"
elif ["$word1" = "$word2"]
then
echo "Match:word 1 & 2"
elif ["$word1" = "$word3"]
then
echo "Match:word 1 & 3"
elif ["$word2" = "$word3"]
then
echo "Match:word 2 & 3"
else
echo "No match"
fi
运行如下:
$ sh if3.sh
word1:apple
word2:orange
word3:pear
[: 23: missing ]
if3.sh: 23: [apple: not found
if3.sh: 23: [apple: not found
if3.sh: 23: [orange: not found
请问问题处在什么地方?
源程序如下:
#! /bin/bash
echo -n "word1:"
read word1
echo -n "word2:"
read word2
echo -n "word3:"
read word3
if [ "$word1" = "$word2" -a "$word2" = "$word3"]
then
echo "Match:word 1 ,2 ,& 3"
elif ["$word1" = "$word2"]
then
echo "Match:word 1 & 2"
elif ["$word1" = "$word3"]
then
echo "Match:word 1 & 3"
elif ["$word2" = "$word3"]
then
echo "Match:word 2 & 3"
else
echo "No match"
fi
运行如下:
$ sh if3.sh
word1:apple
word2:orange
word3:pear
[: 23: missing ]
if3.sh: 23: [apple: not found
if3.sh: 23: [apple: not found
if3.sh: 23: [orange: not found
请问问题处在什么地方?
|
中括号两边都要留空格
|
"$word3"空格]
elif [空格"$word1" = "$word2"空格]
elif [空格"$word1" = "$word3"空格]
elif [空格"$word2" = "$word3"空格]
elif [空格"$word1" = "$word2"空格]
elif [空格"$word1" = "$word3"空格]
elif [空格"$word2" = "$word3"空格]