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 – Stéphane Chazelas Dec 15 '15 at 17:21
  • It may have done, I remember extracting the main context as I didn't think it was important. – user1990366 Dec 15 '15 at 17:29

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

  • Coming from various languages, this always catches me out. Many thanks – user1990366 Dec 15 '15 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 '15 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.