0

I have a simple script as follows:

#!/bin/ksh

JAVA_SRC="/home/myuser/Setup\ Files/jre/bin/java"
eval $JAVA_SRC

When I run this on HP-UX, I get this error:

$ spacetest.sh
/home/myuser/Setup^BFiles/jre/bin/java:  not found

It seems like the shell cannot properly handle the escaped whitespace and is putting garbage instead of the "\ ". This works perfectly fine on other *NIX platforms. If I echo $JAVA_SRC right before the eval, the path shows fine.

Is there any way to properly handle this on HP-UX?

j0k
  • 22,600
  • 28
  • 79
  • 90
Dan
  • 1,763
  • 4
  • 26
  • 40
  • 2
    Why are you eval-ing the variable? I assume you want to invoke java so just `"$JAVA_SRC"` should do that, without the need to escape the space. I suspect there's more to this than you show. – William Jan 30 '13 at 15:42
  • this is actually a simplified example, so JAVA_SRC would be a more complex value with parameters, so I need to use eval. Nevertheless, you're right. I just need to wrap the variable on quotes (eval "$VAR") and that takes care of it – Dan Jan 30 '13 at 15:57
  • @William if you move your comment as an answer I will take it – Dan Feb 05 '13 at 20:18

1 Answers1

0

The solution is to simply, as William suggested above, use quotes around the variable name ("$JAVA_SRC").

Dan
  • 1,763
  • 4
  • 26
  • 40