Please consider this simple script named test:#!/bin/bashecho $1and the following commands and calls:$ echo A BA B$ echo A BA B$ echo A BA B$ echo A BA B$ ./test A BA B$ ./test A BA$ ./test A BA B$ ./test A BACould someone please explain why the call of test doens't behave like the command echo or point to the relevant documentation?
Bash script parsing argument with quotes
shell script;quoting
Because echo concatenates all it arguments to print them, and your script is limited to the first argument. You should use $@ and not $1 in your script.Let's look at the arguments you're providing for your tests:./test A Bone argument, the 3 character string AspaceB./test A Btwo argumentsfirst, empty string concatenated with Asecond, B concatenated with empty string./test A Bone argument, empty string concatenated with AspaceB concatenated with empty string./test A Btwo argumentsfirst, empty string concatenated with empty string concatenated with Asecond, B concatenated with empty string concatenated with empty stringNote: you would see different results from echo if you had used more than one space in your arguments. That's because echo concatenates its arguments with a single space:$ echo A   BA   B$ echo A   BA B$ echo A   BA   B$ echo A   BA B