Reputation: 513
I have the following block in a script to verify whether a mount point is tmpfs
if [ "$(stat -f -c '%T' $LOGDIR)" -ne 'tmpfs' ]
then
echo "Log directory ($LOGDIR) must be tmpfs"
exit 1
fi
The problem is that if the filesystem is returned as ext2/ext3 then the shell attempts to evaluate that and falls over with a division by zero. How can I force it to be treated as a regular string?
Upvotes: 0
Views: 368
Reputation: 530960
Use !=
for string comparison; -ne
is for integer comparison only. (Actually, I'm surprised it tried to do arithmetic using "ext2/ext3", as opposed to simply treating the entire string as a zero value.)
Upvotes: 2
Reputation: 241808
Do not use the -ne
arithmetic operator, use the string operator !=
.
BTW, what version of bash
are you running? I am getting integer expression expected
.
Upvotes: 2