#!/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
Let’s run this:
./trash.sh
./trash.sh: line 3: =/home/someuser/trash: No such file or directory
How can I store this filename in a variable without bash evaluating it? Also: How do I use this variable later for tests?
if [ -e $TRASHDIR ]
then
echo stuff here
fi
Leave the initial
$character off when you define a var:When you use
$TRASHDIR,bashevaluates that as the empty string (or something else if was set previously), which is why it looks like: