【发布时间】:2010-12-15 10:28:03
【问题描述】:
我有一个 shell 脚本,可以让我访问脚本内的全局变量,但是当我尝试创建自己的变量时,它的响应是:找不到命令。
#!/bin/bash
J = 4
FACE_NAME = "eig$J.face"
USER_DB_NAME = "base$J.user"
当我运行上面的脚本时,我得到:
./test1.sh line 2: J: command not found
./test1.sh line 3: FACE_NAME: command not found
./test1.sh line 4: USER_DB_NAME: command not found
有什么想法吗??我在 Windows XP 下使用 Cygwin。
【问题讨论】:
-
在创建变量时不要在变量名中使用全部大写字母。按照惯例,环境变量(PATH、EDITOR、SHELL、...)和内部 shell 变量(BASH_VERSION、RANDOM、...)完全大写。所有其他变量名称应为小写。由于变量名区分大小写,因此此约定可避免意外覆盖环境变量和内部变量。
标签: bash shell variables cygwin