在变量中捕获重定向

时间:2019-03-21 17:52:16

标签: bash redirect

Bash 3.2.57

考虑以下脚本:

return next.handle(request).map((event: HttpEvent<any>) => {
   if (event instanceof HttpResponse && event.body && !event.body.success) {
     throw new HttpErrorResponse({
                        error: 'your error',
                        headers: evt.headers,
                        status: 500,
                        statusText: 'Warning',
                        url: evt.url
                    });
   }
   return event;
);

如上所述运行#!/bin/bash command1="ls" $command1 command2="ls" $command2 >&2 command3="ls >&2" $command3 command1会产生直观的结果。首先将command2打印到 stdout ,然后打印到 stderr
尽管运行第三条命令会产生ls

为什么Bash将ls: >&2: No such file or directory的重定向解释为重定向,而不是command2的重定向?
是否有可能在变量中捕获重定向?

0 个答案:

没有答案