#!/bin/bash
#trash.sh
$TRASHDIR=$HOME/trash
#Does not exist yet, i have loops further in
#the script to check if the dir exists and to create it if not
echo $TRASHDIR
#I have ommited the rest of the script,
#because this is where I have the problem
让我们运行:
./trash.sh
./trash.sh: line 3: =/home/someuser/trash: No such file or directory
如何在没有bash评估的情况下将此文件名存储在变量中?另外:我如何在以后的测试中使用此变量?
if [ -e $TRASHDIR ]
then
echo stuff here
fi
答案 0 :(得分:5)
当定义 var时,请关闭初始的$
字符:
TRASHDIR=$HOME/trash
当你使用$TRASHDIR
时,bash
将其评估为空字符串(或者先前设置的其他内容),这就是它的原因:
=/home/someuser/trash