1

I have code like the following

flags->add_option("--name", name_, "The name.")->required();

I want to be able to pass strings like "aa$p$aa" to the --name parameter. However, this does not seem to work with CLI11, and the name gets truncated to just "aa". I need to escape the $ characters to properly read the strings. So aa\$p\$aa works fine, and I get the expected string ("aa$p$aa").

Changing the function to add_flag() does not work either.

Is there a way to be able to pass arbitrary strings to a parameter as with either function calls above?

Curious
  • 20,870
  • 8
  • 61
  • 146
  • 1
    This has nothing to do, whatsoever, with any parameter to any function. This is how your operating system works, when you use it to run your program and provide arguments to the program being executed. There's nothing that any C++ program can do to change that. – Sam Varshavchik Jun 09 '22 at 01:48
  • @SamVarshavchik ugh yes, of course, thanks! Want to turn that comment into an answer? – Curious Jun 09 '22 at 01:52
  • If $ and \ and * are special to the shell then you are probably using Linux. Window's command line thinks ^ and % are special. The parameter substitution happens before your program is executed. You could always put single quotes around the parameters but you have to escape the single quotes inside your parameters. Here is a question about turning off all that stuff (no answers) https://stackoverflow.com/questions/42114878/disable-histexpand-and-variable-substitution – Jerry Jeremiah Jun 09 '22 at 04:05
  • Here are some questions that might be duplicates of yours: https://stackoverflow.com/questions/2617453/controlling-shell-command-line-wildcard-expansion-in-c-or-c https://stackoverflow.com/questions/15209718/turn-off-bash-variable-substitution – Jerry Jeremiah Jun 09 '22 at 04:07

1 Answers1

2

Your operating system takes the command you type in and executes the given program, passing the parameters to it.

The interpolation, and the handling of $ characters in typed-in commands is handled by your operating system as part of executing the typed-in command. Your compiled C++ program receives the transformed arguments, as parameters. Your C++ program has no means to control what has happened before it was even executed.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148