[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] storing a command in a variable

From: John Kearney
Subject: Re: [Help-bash] storing a command in a variable
Date: Mon, 15 Apr 2013 15:30:59 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5

Am 15.04.2013 14:30, schrieb Greg Wooledge:
> On Sat, Apr 13, 2013 at 01:47:58AM +0200, John Kearney wrote:
>> I normally advise
>> run_cmd() {
>>     local RValue=0
>>     printf "%q" "address@hidden"; echo
>>     "address@hidden" || RValue=$?
>>     [ ${RValue} = 0  ] || echo "Returned (${RValue}) ${*}"
>>     return ${RValue}
>> }
>> run_cmd command arg
> The problem is that you can only run simple commands this way --
> no pipelines, no compound commands.
Sure I can I just don't try to take the whole line :).
run_cmd command arg && run_cmd command2 arg | run_cmd command arg

Ok I know not what you meant.
I avoid the need to do what you are talking about. I notmally only use 
something like run_cmd for external operations. 
I only use compound commands and piping etc at a different level.

sorry this is off the top of my head, but I used to use something like.

run_cmd_redirect() {
    local OutFile=${1:-1}
    local RValue=0
    printf "%q" "address@hidden"; echo ">${OutFile}"
    case ${OutFile} in
          "address@hidden" >&${OutFile} || RValue=$?
          "address@hidden" >>${OutFile:1} || RValue=$?
          "address@hidden" || RValue=$?
          "address@hidden" >${OutFile} || RValue=$?
    [ ${RValue} = 0  ] || echo "Returned (${RValue}) ${*}"
    return ${RValue}

though in the end I decided I needing that sort of function was just the 
incorrect approach.

Though set -x is also not really an option for me I tend to have 100+
operations to each command I'm interested in. so if i try to use set -x
I end up with 10000+ lines to go through.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]