我正在尝试编写一个bash脚本,以自动将我的构建和源目录(具有共享对象二进制文件)中的文件分别复制到我的系统/usr/lib
和/usr/include
目录。
当我运行以下内容时:
#!/bin/bash
RELEASE_ARG = "--release"
DEBUG_ARG = "--debug"
DEST_NAME = "libEngine.so"
SRC_NAME = "libEngineSO.so"
ENGINE_DBG_DEST = "/usr/lib/Stitches/Debug/$DEST_NAME"
ENGINE_REL_DEST = "/usr/lib/Stitches/Release/$DEST_NAME"
ENGINE_REL_SRC = "$STITCH_ROOT/Engine__Release/$SRC_NAME"
ENGINE_DBG_SRC = "$STITCH_ROOT/Engine__Debug/$SRC_NAME"
if [ ! -z $1 ]; then
#foo
echo "No argument specified; please specify either ${RELEASE_ARG} or $DEBUG_ARG. K BAI\n"
exit
elif [ -z $1 -eq RELEASE_ARG ]; then
#wat
echo "If you actually chose this option, you better be damn ready to distribute...\n"
echo "Updating Release directory in $ENGINE_REL_DEST\n"
cp $ENGINE_REL_SRC $ENGINE_REL_DEST
elif [ -z $1 -eq DEBUG_ARG ]; then
#reasonable and realistic
echo "Good choice...\n"
echo "Updating Debug directory in $ENGINE_DBG_DEST\n"
cp $ENGINE_DBG_SRC $ENGINE_DBG_DEST
fi
echo "Sex ;)"
我得到了这个输出:
x@x ~/Programming/Stitches-Qt/scripts $ sh postbuild.sh --debug
postbuild.sh: 3: postbuild.sh: DEBUG: not found
postbuild.sh: 5: postbuild.sh: RELEASE_ARG: not found
postbuild.sh: 6: postbuild.sh: DEBUG_ARG: not found
postbuild.sh: 8: postbuild.sh: DEST_NAME: not found
postbuild.sh: 10: postbuild.sh: SRC_NAME: not found
postbuild.sh: 12: postbuild.sh: ENGINE_DBG_DEST: not found
postbuild.sh: 13: postbuild.sh: ENGINE_REL_DEST: not found
postbuild.sh: 15: postbuild.sh: ENGINE_REL_SRC: not found
postbuild.sh: 16: postbuild.sh: ENGINE_DBG_SRC: not found
No argument specified; please specify either or . K BAI
正如您所看到的,我必须使用不正确的变量或其他东西。我如何完成我在这里要做的事情?
P.S。,我知道除非我是root用户,否则我不能这样做,所以我在/usr/lib
|中创建了一个子目录。 /usr/include
所以我可以将其添加到我的用户名中。所以,这应该有用......
答案 0 :(得分:4)
你不能在bash中使用任意空格。
RELEASE_ARG="--release"
DEBUG_ARG="--debug"
使用test
时应引用。
if [ ! -z "$1" ]; then