Skip to main content
added 519 characters in body
Source Link
l0b0
  • 53.6k
  • 48
  • 225
  • 398

You can use eval, but the next maintainer will curse your name. Have you tried just appending the variable when using the parsed data, or expanding the variable when creating the data?

If the file is created that way, can't you just use some [redacted] techniques to convince the originator to change their wicked ways?

If change is literally not possible, then you must have control over which variables are possible. Otherwise your script is vulnerable to all sorts of injection attacks, such as inputs like 3|sample1.txt|$(rm --arr --eff /)/operation/. Since you obviously have that under control, you can do some literal replacements of variables with their values on a case by case basis:

IFS='/' read -a pathnames <<< "$fpath"
for pathname in "${pathnames[@]}"
do
    if [ "${pathname::1}" = '$' ]
    then
        variable_name="${pathname:1}"
        printf '%s' "${!variable_name}"
    else
        printf '%s' "$pathname"
    fi
done

With some additional boilerplate to add slashes between pathnames.

You can use eval, but the next maintainer will curse your name. Have you tried just appending the variable when using the parsed data, or expanding the variable when creating the data?

If the file is created that way, can't you just use some [redacted] techniques to convince the originator to change their wicked ways?

If change is literally not possible, then you must have control over which variables are possible. Otherwise your script is vulnerable to all sorts of injection attacks, such as inputs like 3|sample1.txt|$(rm --arr --eff /)/operation/. Since you obviously have that under control, you can do some literal replacements of variables with their values on a case by case basis.

You can use eval, but the next maintainer will curse your name. Have you tried just appending the variable when using the parsed data, or expanding the variable when creating the data?

If the file is created that way, can't you just use some [redacted] techniques to convince the originator to change their wicked ways?

If change is literally not possible, then you must have control over which variables are possible. Otherwise your script is vulnerable to all sorts of injection attacks, such as inputs like 3|sample1.txt|$(rm --arr --eff /)/operation/. Since you obviously have that under control, you can do some literal replacements of variables with their values on a case by case basis:

IFS='/' read -a pathnames <<< "$fpath"
for pathname in "${pathnames[@]}"
do
    if [ "${pathname::1}" = '$' ]
    then
        variable_name="${pathname:1}"
        printf '%s' "${!variable_name}"
    else
        printf '%s' "$pathname"
    fi
done

With some additional boilerplate to add slashes between pathnames.

added 519 characters in body
Source Link
l0b0
  • 53.6k
  • 48
  • 225
  • 398

You can use eval, but the next maintainer will curse your name. Have you tried just appending the variable when using the parsed data, or expanding the variable when creating the data?

If the file is created that way, can't you just use some [redacted] techniques to convince the originator to change their wicked ways?

If change is literally not possible, then you must have control over which variables are possible. Otherwise your script is vulnerable to all sorts of injection attacks, such as inputs like 3|sample1.txt|$(rm --arr --eff /)/operation/. Since you obviously have that under control, you can do some literal replacements of variables with their values on a case by case basis.

You can use eval, but the next maintainer will curse your name. Have you tried just appending the variable when using the parsed data, or expanding the variable when creating the data?

You can use eval, but the next maintainer will curse your name. Have you tried just appending the variable when using the parsed data, or expanding the variable when creating the data?

If the file is created that way, can't you just use some [redacted] techniques to convince the originator to change their wicked ways?

If change is literally not possible, then you must have control over which variables are possible. Otherwise your script is vulnerable to all sorts of injection attacks, such as inputs like 3|sample1.txt|$(rm --arr --eff /)/operation/. Since you obviously have that under control, you can do some literal replacements of variables with their values on a case by case basis.

Source Link
l0b0
  • 53.6k
  • 48
  • 225
  • 398

You can use eval, but the next maintainer will curse your name. Have you tried just appending the variable when using the parsed data, or expanding the variable when creating the data?