Skip to main content
Post Closed as "Duplicate" by Kusalananda bash
Minor formatting, remove duplicating tag
Source Link
AdminBee
  • 23.6k
  • 25
  • 56
  • 77

I'm trying to run a command in a bash variable, like this:

cmd="python -m mymodule 'argument 123 456' argument2=32 argument3=234"
$cmd
cmd="python -m mymodule 'argument 123 456' argument2=32 argument3=234"
$cmd

It looks like it is splitting the command line arguments in the first string even though it is surrounded with single quotes:

['argument', '123', '456', 'argument2=32', 'argument3=234']

['argument', '123', '456', 'argument2=32', 'argument3=234']

Is there anything I can do to prevent this? I've tried to use esacped double-quotes \", backticks `, but nothing works, it will still split the first command line argument on the spaces.

I'm trying to run a command in a bash variable, like this:

cmd="python -m mymodule 'argument 123 456' argument2=32 argument3=234"
$cmd

It looks like it is splitting the command line arguments in the first string even though it is surrounded with single quotes:

['argument', '123', '456', 'argument2=32', 'argument3=234']

Is there anything I can do to prevent this? I've tried to use esacped double-quotes \", backticks `, but nothing works, it will still split the first command line argument on the spaces.

I'm trying to run a command in a bash variable, like this:

cmd="python -m mymodule 'argument 123 456' argument2=32 argument3=234"
$cmd

It looks like it is splitting the command line arguments in the first string even though it is surrounded with single quotes:

['argument', '123', '456', 'argument2=32', 'argument3=234']

Is there anything I can do to prevent this? I've tried to use esacped double-quotes \", backticks `, but nothing works, it will still split the first command line argument on the spaces.

Source Link

Prevent splitting command line argument at spaces when running in bash script

I'm trying to run a command in a bash variable, like this:

cmd="python -m mymodule 'argument 123 456' argument2=32 argument3=234"
$cmd

It looks like it is splitting the command line arguments in the first string even though it is surrounded with single quotes:

['argument', '123', '456', 'argument2=32', 'argument3=234']

Is there anything I can do to prevent this? I've tried to use esacped double-quotes \", backticks `, but nothing works, it will still split the first command line argument on the spaces.