Is it possible to do a bash brace expansion using a variable bound without using eval?

前端 未结 3 1311
臣服心动
臣服心动 2021-01-27 02:59

Consider the following script.

#!/bin/bash

echo {00..99}
n=99
echo {00..$n}

The output of this script is:

00 01 02 03 04 05 06         


        
3条回答
  •  执笔经年
    2021-01-27 03:21

    From the bash manual:

    The order of expansions is: brace expansion; tilde expansion, parameter and variable expansion, arithmetic expansion, and command substitution (done in a left-to-right fashion); word splitting; and pathname expansion.

    Given that variable expansion comes after brace expansion, and that there is no way to induce a different order of operations without using eval, I would have to conclude that no, there is no way to avoid using eval.

提交回复
热议问题