Skip to main content
added 2 characters in body
Source Link
ilkkachu
  • 148.1k
  • 16
  • 268
  • 441

The safe way to interpolate a variable into a string is to use ${var_name}. For example:

#!/bin/bash

devName="/dev/sda"
devTarget=$devTarget="${devName}33"

echo "$devTarget"

This way Bash has no doubts of what the variable to interpolate is.

Btw, interesting how devTarget=$devName\3 works. I'm not sure why.

The safe way to interpolate a variable into a string is to use ${var_name}. For example:

#!/bin/bash

devName="/dev/sda"
devTarget=${devName}3

echo "$devTarget"

This way Bash has no doubts of what the variable to interpolate is.

Btw, interesting how devTarget=$devName\3 works. I'm not sure why.

The safe way to interpolate a variable into a string is to use ${var_name}. For example:

#!/bin/bash

devName="/dev/sda"
devTarget="${devName}3"

echo "$devTarget"

This way Bash has no doubts of what the variable to interpolate is.

Btw, interesting how devTarget=$devName\3 works. I'm not sure why.

Source Link
user147505
user147505

The safe way to interpolate a variable into a string is to use ${var_name}. For example:

#!/bin/bash

devName="/dev/sda"
devTarget=${devName}3

echo "$devTarget"

This way Bash has no doubts of what the variable to interpolate is.

Btw, interesting how devTarget=$devName\3 works. I'm not sure why.