0

I've got a little go tool found here: https://github.com/deusdat/gocrypttool

It takes two command line arguments: the clear text password to encrypt and the cost of the bcrypt.

If I run the command with two arguments, it works fine. When I run the command gocrypttool "$(< example)" where the file example exists, and holds the same two command line arguments, I get 2018/06/19 12:03:23 Please provide the password and the cost. This error indicates that the binary didn't get arguments.

How, without adding a command line interface with prompts, can I read a file for arguments to a go binary?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Virmundi
  • 2,497
  • 3
  • 25
  • 34
  • @TimCooper If you want to make that comment the answer I'll take it. I see that is more of a bash issue (and operator issue). On the plus side, Google finds jack about this so you might get a good reach of help. – Virmundi Jun 19 '18 at 16:15
  • @TimCooper, please don't encourage unquoted expansion -- you get globbing as a result, and it's almost always unwanted. – Charles Duffy Jun 19 '18 at 16:16
  • @CharlesDuffy: I know, this should be preferred: https://stackoverflow.com/questions/6585064/how-to-pass-command-line-parameters-from-a-file –  Jun 19 '18 at 16:16
  • The only **safe** way to store arbitrary command-line parameters in a file is in NUL-delimited form. Thus, `printf '%s\0' "$arg1" "$arg2" ... >file`, then `args=( ); while IFS= read -r -d '' arg; do args+=( "$arg" ); done – Charles Duffy Jun 19 '18 at 16:16
  • @TimCooper, no, `xargs` without either `-0` or `-d` arguments isn't safe with arbitrary arguments either; by default, it tries to be shell-compatible in its parsing, but the results are subtly buggy. – Charles Duffy Jun 19 '18 at 16:17
  • @Virmundi, how are the two values in the file separated? Spaces? Are they quoted? What **exactly** is the format? – Charles Duffy Jun 19 '18 at 16:18
  • ...the above `IFS= read -r -d ''` loop is *close* to what `xargs -0 somecommand – Charles Duffy Jun 19 '18 at 16:20
  • Space separated. password as a string and the cost as an integer. – Virmundi Jun 19 '18 at 16:49

0 Answers0