In an effort of keeping things DRY, I am trying to assign a path to a variable that may not exist and have the following script which returns:

/apps/tmp: No such file or directory



if [ -d $WORKDIR ]; then 
    rm -rf $WORKDIR

Is this possible or what work around is there?

  • I'd expect the error to be myscript: 3: =/apps/tmp: No such file or directory Dec 15, 2015 at 17:21
  • It may have done, I remember extracting the main context as I didn't think it was important. Dec 15, 2015 at 17:29

1 Answer 1


When you create new variable, you are not using dollar $ sign. Just do:

  • Coming from various languages, this always catches me out. Many thanks Dec 15, 2015 at 17:29
  • Yes. I know. Especially from PHP the syntax is just in the back of your head. You are welcome. And of course, welcome to Unix & Linux!
    – Jakuje
    Dec 15, 2015 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.