开发者

error on pipe in bash script

开发者 https://www.devze.com 2023-03-24 15:36 出处:网络
part of my bash script is A=\"-a\"开发者_Python百科 B=\"|more\" ls $A $B when executing this script, it complained \"|more\" not found.

part of my bash script is

A="-a"开发者_Python百科
B="|more"
ls $A $B

when executing this script, it complained "|more" not found. How to use pipelines in bash script commands then please?


Maybe like this:

eval "ls $A $B"

?


I think what you may be trying for is implementing some sort of variable that controls whether the data is piped through a pager.

You may be better off using alias:

if [ "$USING_PAGER" -ne 0 ]; then
    alias B='more'
else
    alias B='cat'
fi

ls $A |B


ls -a |more

also fails - there is no such command in bash.

0

精彩评论

暂无评论...
验证码 换一张
取 消