0
#!/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
4

1 回答 1

5

定义var$时,请关闭初始字符:

TRASHDIR=$HOME/trash

当您使用$TRASHDIR时,bash将其评估为空字符串(或之前设置的其他内容),这就是它看起来像这样的原因:

=/home/someuser/trash
于 2012-08-07T07:53:35.077 回答