How to run script commands from variables?

后端 未结 3 1127
感情败类
感情败类 2021-01-04 20:54

I tried to run commands using pipes.

Basic:

single=\"ls -l\"
$single

which works as expected

Pipes

3条回答
  •  礼貌的吻别
    2021-01-04 21:28

    when you want to run commands with pipes, just run it. Don't ever put the command into a variable and try to run it. Simply execute it

    ls -l |grep

    If you want to capture the output, use $()

    var=$(ls -l |grep .. )

提交回复
热议问题