Hacker News new | past | comments | ask | show | jobs | submit login

A bit hard to understand your exact scenario here (basically the same shell lexing problem...), but I think this is what you're looking for.

I left an example of an argument with a space in there (the last one).

    PROPS=("-Dprop1=foo" "bar" "-Dprop2=bar foo")
    java "${PROPS[@]}" SomeClass.class
(The quotes around `${PROPS[@]}` is important.) Do note, there is an unfortunate edge case here if PROPS is empty, you'll get a false `""` arg passed to java in that case. There's a less pleasant syntax that avoids that issue but I don't recall it off-hand.

(edit: Please read the replies to my post, I didn't think about the fact that this syntax is bash specific. Thanks to those who pointed it out)




Oh I am sure there are ways around it but the big issue is that almost all of the daemon scripts out there do not do it. That is you can't just set some configuration in /etc/default/some_daemon as the script will try to concatenate the command.

I tried to find a failsafe solution once while rewriting a daemon script and just gave up.


That's a bashism I think and hence not as portable as POSIX shells.


This is, of course, a bashism.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: