0

I'm having the following issue. When I execute this command sfdx profile:field:add -n "Account.Test" -m re -p "Test" from a Bash script, it's all fine.

However, when I try to execute the following: sfdx profile:field:add -n "Account.Test" -m re -p "Test Test" I get this error: 'C:\Program' is not recognized as an internal or external command

When I run the same command in the terminal, it works fine. It's just when I put it inside a bash script that this error happens.

Currently running this on Windows 10.

I'm 100% sure it's the space in that last parameter, I am just not sure how to get around it. Can anyone help?

  • 1
    Bash has no problem with parameters that contain spaces, as long as proper quoting is done in the code. The quoting here looks good. The problem may be in `sfdx`. To narrow down the location of the problem, run your Bash program with tracing turned on. E.g. `bash -x progname arg1 arg2`. See [How can I debug a Bash script?](https://stackoverflow.com/q/951336/4154375). – pjh Mar 18 '22 at 14:01
  • 1
    Also, run your program through [Shellcheck](https://www.shellcheck.net/) to make sure that there are no quoting issues (or other common issues) lurking elsewhere in it. – pjh Mar 18 '22 at 14:03
  • Just ran the command that you mentioned and the problem is the command expects that parameter to be between double quotes, but bash gets rid of the double quotes when it executes it... I tried escaping the characters but then I get the string between single quotes. This is what I get when I do bash -x ./../client/bin/sfdx.cmd profile:field:add -n Account.Test -m re -p '"Test Test"' – Gaby Zamfir Mar 18 '22 at 15:07
  • If the command *really* expects `"Test Test"` as an argument instead of `Test Test`, then the output that you are seeing is what I would expect. Tracing shows `'"Test Test"'` because that's one way that the argument could be quoted in the Bash code. With that code, the executed command will see `"Test Test"` (Bash removes single quotes around arguments before passing them to commands.) As another example, Bash code `echo 'Hello World'` and `echo "Hello World"` do exactly the same thing. In both cases `echo` just sees `Hello World`. – pjh Mar 18 '22 at 15:16
  • I think that package (sfdx) not me that developed it... expects that last parameter to be between double quotes. So if I run `sfdx profile:field:add -n Account.Test -m re -p 'Test Test'` I get an error... If I run `sfdx profile:field:add -n Account.Test -m re -p "Test Test"` I don't... so my question is how do I force the bash script to use double quotes when using variables in the script? because when I do bash -x the output shows that the script uses single quotes which I think breaks it – Gaby Zamfir Mar 18 '22 at 15:38
  • The script uses exactly the quotes that you put in it. The `bash -x` output may show something different, but equivalent. If you want the called program to see `"Test Test"` (including the quotes) as an argument then one way to code it is `'"Test Test"'`. Another is `"\"Test Test\""`. Another is `\"Test\ Test\"`. The program sees exactly the same argument (`"Test Test"`) in all cases. – pjh Mar 18 '22 at 15:48
  • 1
    `sfdx profile:field:add -n Account.Test -m re -p 'Test Test'` and `sfdx profile:field:add -n Account.Test -m re -p "Test Test"` are **exactly** equivalent as Bash code. If you are getting different results with them then they are not being run in the same way (e.g. different windows with different environments) or they are not being run by Bash. Try putting them both, one after the other, in a file and run it. If they produce different results then swap the order and try again (I'd guess the first one may be messing up something used by the second one). – pjh Mar 18 '22 at 15:56
  • 1
    The error message "'C:\Program' is not recognized as an internal or external command" is something I'd expect to see from a batch (ye olde DOS script language) script, not a bash (unix scripting language, similarly named but completely different) script. Are you sure this is running in bash, not as a batch script? – Gordon Davisson Mar 18 '22 at 18:09

0 Answers0