0

I have bat (file.bat) file with the following lines:

echo "Upgrading..."
cp %1/global/a-* %2/global/

I run in CMD the following:

bash file.bat /opt/ad-kf041f /srv/

As I understand, it should put the parameters instead of the %num, but it doesn't and I get:

cp: cannot stat `%1/global/a-*': No such file or directory

As you can see, I try the suggestion of this question, but it still gives me the same error.

I also try:

set  arg1=%1
echo %arg1%

and it prints: %arg1%

Where am I wrong?

Community
  • 1
  • 1
MIDE11
  • 3,140
  • 7
  • 31
  • 53
  • 2
    Possible duplicate of [How to pass command line parameters to a batch file?](http://stackoverflow.com/questions/26551/how-to-pass-command-line-parameters-to-a-batch-file) – ΦXocę 웃 Пepeúpa ツ Oct 17 '15 at 11:31
  • Try to equal new variable to the `%1` first: `SET PARAM=%1` and then cobcatenate with the var: `%PARAM%/global/a-*` – Timofey Oct 17 '15 at 11:34
  • 2
    You mix up the unix and windows scripts, please specify what kind of script you need. – Timofey Oct 17 '15 at 12:17

1 Answers1

0

If you're running the file with bash, it's a bash script, not a "batch file". The bash syntax for command line arguments is

cp "$1"/global/a-* "$2"/global/
melpomene
  • 84,125
  • 8
  • 85
  • 148
  • Regardless of whether this is a bash or cmd shell script, it should check, at a minimum, check the exit code to see that the copy worked. Checking to see that the parameters exist before using them would be a good idea as well. – lit Oct 17 '15 at 14:35