#!/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
讓我們來運行這個命令:防止BASH從評估的變量名
./trash.sh
./trash.sh: line 3: =/home/someuser/trash: No such file or directory
我如何可以存儲這個文件名中沒有慶典計算它的變量?另外:以後如何使用這個變量進行測試?
if [ -e $TRASHDIR ]
then
echo stuff here
fi
你也應該雙引號你的變量插值。變量發生在美元符號的任何地方,你想把它放在雙引號內。 – tripleee 2012-08-07 07:57:52
如果你使用'[[',即使它包含嵌入空格:'if [[-e $ TRASHDIR]]' – cdarke 2012-08-07 08:39:04