0

How to execute command from string containing spaces?

$ ls "xxx yyy"
a.exe

$ X="./xxx yyy/a.exe" ; $X
-bash: ./xxx: No such file or directory

$ X='./xxx yyy/a.exe' ; $X
-bash: ./xxx: No such file or directory

$ X="./xxx\ yyy/a.exe" ; $X
-bash: ./xxx\: No such file or directory

How? Any ideas?


UPD. Found: $ X="./xxx yyy/a.exe" ; "$X".


UPD2. But I cannot pass arguments to it. This: $ X="./xxx yyy/a.exe" ; "$X" xxx does not pass xxx to $X. Hot to do it? Any help? This $ X="./xxx\ yyy/a.exe" ; eval $X xxx seems to work, but why there is a need to use eval? Is it possible to avoid eval?

To pass arguments use $ X="./xxx yyy/a.exe" ; "$X" xxx.

pmor
  • 509
  • 5
  • 11
  • "`$ X="./xxx yyy/a.exe" ; "$X" xxx` does not pass `xxx` to `$X`" ... that works fine enough for me. – muru Apr 09 '22 at 11:27
  • @muru Ah, right! Thanks! I've mistakenly used `"$(X)" xxx` instead of `"$X" xxx`. – pmor Apr 09 '22 at 11:33

0 Answers0