分页: 1 / 1

bash脚本中while的判断条件不能成立

发表于 : 2011-10-21 12:46
Mr沛

代码: 全选

#! /bin/bash
opt="z"
until ["$opt"="x"];
do
        echo "a. List all files in the present working directory"
        echo "b. Display today's date and time, and your Linux version"
        echo "c. Invoke the shell script of Problem 2"
        echo "d. Display whether a file is a \"simple\" file or a \"directory\""
        echo "e. Create a backup for a file"
        echo "f. Start an ftp session to our course site"
        echo "x. Exit"
        echo "Please enter an option:"
        read opt
done
        echo "Bye-Bye"
就想做一个选项选择,运行的时候提示如下

代码: 全选

./work1: 行 4: [z=x]: 未找到命令
a. List all files in the present working directory
b. Display today's date and time, and your Linux version
c. Invoke the shell script of Problem 2
d. Display whether a file is a "simple" file or a "directory"
e. Create a backup for a file
f. Start an ftp session to our course site
x. Exit
Please enter an option:
会有一个这个

代码: 全选

./work1: 行 4: [z=x]: 未找到命令
我觉得应该是while的判断条件有错,不知道正确的格式应该怎么样

Re: bash脚本中while的判断条件不能成立

发表于 : 2011-10-21 13:10
lilydjwg
空格啊空格。。。。
[bash]
[ "$opt" = "x" ]
[/bash]
[ 是程序名,后面四项都是它的参数。

Re: bash脚本中while的判断条件不能成立

发表于 : 2011-10-21 13:19
Mr沛
lilydjwg 写了:空格啊空格。。。。
[bash]
[ "$opt" = "x" ]
[/bash]
[ 是程序名,后面四项都是它的参数。
哦,非常感谢 :em05