Skip to main content
added 308 characters in body
Source Link
glenn jackman
  • 88.6k
  • 16
  • 124
  • 179

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 B"
    • one argument, the 3 character string AspaceB
  • ./test ""A B""
    • two arguments
      • first, empty string concatenated with A
      • second, B concatenated with empty string
  • ./test """A B"""
    • one argument, empty string concatenated with AspaceB concatenated with empty string
  • ./test """"A B""""
    • two arguments
      • first, empty string concatenated with empty string concatenated with A
      • second, B concatenated with empty string concatenated with empty string

Note: 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   B"
A   B
$ echo ""A   B""
A B
$ echo """A   B"""
A   B
$ echo """"A   B""""
A B

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 B"
    • one argument, the 3 character string AspaceB
  • ./test ""A B""
    • two arguments
      • first, empty string concatenated with A
      • second, B concatenated with empty string
  • ./test """A B"""
    • one argument, empty string concatenated with AspaceB concatenated with empty string
  • ./test """"A B""""
    • two arguments
      • first, empty string concatenated with empty string concatenated with A
      • second, B concatenated with empty string concatenated with empty string

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 B"
    • one argument, the 3 character string AspaceB
  • ./test ""A B""
    • two arguments
      • first, empty string concatenated with A
      • second, B concatenated with empty string
  • ./test """A B"""
    • one argument, empty string concatenated with AspaceB concatenated with empty string
  • ./test """"A B""""
    • two arguments
      • first, empty string concatenated with empty string concatenated with A
      • second, B concatenated with empty string concatenated with empty string

Note: 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   B"
A   B
$ echo ""A   B""
A B
$ echo """A   B"""
A   B
$ echo """"A   B""""
A B
added 780 characters in body
Source Link
glenn jackman
  • 88.6k
  • 16
  • 124
  • 179

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 B"
    • one argument, the 3 character string AspaceB
  • ./test ""A B""
    • two arguments
      • first, empty string concatenated with A
      • second, B concatenated with empty string
  • ./test """A B"""
    • one argument, empty string concatenated with AspaceB concatenated with empty string
  • ./test """"A B""""
    • two arguments
      • first, empty string concatenated with empty string concatenated with A
      • second, B concatenated with empty string concatenated with empty string

Because echo concatenates all it arguments to print them, and your script is limited to the first argument.

Let's look at the arguments you're providing for your tests:

  • ./test "A B"
    • one argument, the 3 character string AspaceB
  • ./test ""A B""
    • two arguments
      • first, empty string concatenated with A
      • second, B concatenated with empty string
  • ./test """A B"""
    • one argument, empty string concatenated with AspaceB concatenated with empty string
  • ./test """"A B""""
    • two arguments
      • first, empty string concatenated with empty string concatenated with A
      • second, B concatenated with empty string concatenated with empty string

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 B"
    • one argument, the 3 character string AspaceB
  • ./test ""A B""
    • two arguments
      • first, empty string concatenated with A
      • second, B concatenated with empty string
  • ./test """A B"""
    • one argument, empty string concatenated with AspaceB concatenated with empty string
  • ./test """"A B""""
    • two arguments
      • first, empty string concatenated with empty string concatenated with A
      • second, B concatenated with empty string concatenated with empty string
added 780 characters in body
Source Link
glenn jackman
  • 88.6k
  • 16
  • 124
  • 179

Because echo concatenates all it arguments to print them, and your script is limited to the first argument.

(details to follow) Let's look at the arguments you're providing for your tests:

  • ./test "A B"
    • one argument, the 3 character string AspaceB
  • ./test ""A B""
    • two arguments
      • first, empty string concatenated with A
      • second, B concatenated with empty string
  • ./test """A B"""
    • one argument, empty string concatenated with AspaceB concatenated with empty string
  • ./test """"A B""""
    • two arguments
      • first, empty string concatenated with empty string concatenated with A
      • second, B concatenated with empty string concatenated with empty string

Because echo concatenates all it arguments to print them, and your script is limited to the first argument.

(details to follow)

Because echo concatenates all it arguments to print them, and your script is limited to the first argument.

Let's look at the arguments you're providing for your tests:

  • ./test "A B"
    • one argument, the 3 character string AspaceB
  • ./test ""A B""
    • two arguments
      • first, empty string concatenated with A
      • second, B concatenated with empty string
  • ./test """A B"""
    • one argument, empty string concatenated with AspaceB concatenated with empty string
  • ./test """"A B""""
    • two arguments
      • first, empty string concatenated with empty string concatenated with A
      • second, B concatenated with empty string concatenated with empty string
Source Link
glenn jackman
  • 88.6k
  • 16
  • 124
  • 179
Loading