Skip to main content
added 41 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

In a script, you should not demote an array to a string. An environment variable and its value is a simple key=value pair where both key and value are strings. Demoting the positional parameters to a simple string (by concatenation) will make it difficult to retain separation between them, and it would be hard to get quoting right when you end up wanting to use them.

Instead, pass the positional parameters (command line argument) that you want to pass to the next script on its command line.

#!/bin/bash

first_arg=$1
shift
    
# later ...

./my_other_script "$@"

In the other script:

#!/bin/bash

# use "$@" here
foo --bar "$@"

In a script, you should not demote an array to a string. An environment variable and its value is a simple key=value pair. Demoting the positional parameters to a simple string (by concatenation) will make it difficult to retain separation between them, and it would be hard to get quoting right when you end up wanting to use them.

Instead, pass the positional parameters (command line argument) that you want to pass to the next script on its command line.

#!/bin/bash

first_arg=$1
shift
    
# later ...

./my_other_script "$@"

In the other script:

#!/bin/bash

# use "$@" here
foo --bar "$@"

In a script, you should not demote an array to a string. An environment variable and its value is a simple key=value pair where both key and value are strings. Demoting the positional parameters to a simple string (by concatenation) will make it difficult to retain separation between them, and it would be hard to get quoting right when you end up wanting to use them.

Instead, pass the positional parameters (command line argument) that you want to pass to the next script on its command line.

#!/bin/bash

first_arg=$1
shift
    
# later ...

./my_other_script "$@"

In the other script:

#!/bin/bash

# use "$@" here
foo --bar "$@"
added 244 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

In a script, you should not demote an array to a string. An environment variable and its value is a simple key=value pair. Demoting the positional parameters to a simple string (by concatenation) will make it difficult to retain separation between them, and it would be hard to get quoting right when you end up wanting to use them.

Instead, pass the positional parameters (command line argument) that you want to pass to the next script on its command line.

#!/bin/bash

first_arg=$1
shift
    
# later ...

./my_other_script "$@"

In the other script:

#!/bin/bash

# use "$@" here
foo --bar "$@"

In a script, you should not demote an array to a string.

#!/bin/bash

first_arg=$1
shift
    
# later ...

./my_other_script "$@"

In the other script:

#!/bin/bash

# use "$@" here
foo --bar "$@"

In a script, you should not demote an array to a string. An environment variable and its value is a simple key=value pair. Demoting the positional parameters to a simple string (by concatenation) will make it difficult to retain separation between them, and it would be hard to get quoting right when you end up wanting to use them.

Instead, pass the positional parameters (command line argument) that you want to pass to the next script on its command line.

#!/bin/bash

first_arg=$1
shift
    
# later ...

./my_other_script "$@"

In the other script:

#!/bin/bash

# use "$@" here
foo --bar "$@"
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

In a script, you should not demote an array to a string.

#!/bin/bash

first_arg=$1
shift
    
# later ...

./my_other_script "$@"

In the other script:

#!/bin/bash

# use "$@" here
foo --bar "$@"