【问题标题】:Creating Alias For List of Arguments in Bash为 Bash 中的参数列表创建别名
【发布时间】:2011-07-06 23:33:59
【问题描述】:

我想知道是否有任何方法可以为参数列表创建别名。

考虑以下命令:

my_command --class_a_argument_one --class_a_argument_two --class_a_argument_three --class_a_argument_four

my_command --class_b_argument_one --class_b_argument_two --class_b_argument_three --class_b_argument_four

my_second_command --class_a_argument_one --class_a_argument_two --class_a_argument_three --class_a_argument_four

我想为每个参数列表创建两个不同的别名,以便我可以使用这些命令运行这两个命令:

my_command class_a_arguments
my_second_command class_a_arguments
my_command class_b_arguments

有什么想法吗?

【问题讨论】:

    标签: bash arguments alias


    【解决方案1】:

    将参数放入数组中,然后使用该数组调用命令。

    $ arr1=(-e '\e[32mHello world\e[0m')
    $ echo "${arr1[@]}"
    Hello world
    

    【讨论】:

      【解决方案2】:

      它们被称为变量。

      A="foo bar"
      B="baz qoox"
      my_command $A
      your_command $B
      

      【讨论】:

      • 是的,我知道。不过他好像是个shell新手,如果有必要遇到这个问题对他有好处。
      猜你喜欢
      • 2012-07-13
      • 2012-02-16
      • 1970-01-01
      • 2021-08-03
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多