首页 文章

为什么echo和print命令会在shell脚本中生成箭头符号( - >)?

提问于
浏览
-2

我运行一个ksh脚本并且里面有“echo”和“print”命令,这有点棘手 . 并且输出包含箭头符号 - > . 喜欢:

->   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
->                                  Dload  Upload   Total   Spent    Left  Speed
-> 
  0  4374    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0  4374    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
101  4374    0     0  101  4374      0   2934  0:00:01  0:00:01 --:--:--  4072
100  4642  134   268  101  4374    152   2491  0:00:01  0:00:01 --:--:--  3264

-> This is FLAG!!!
   stty: standard input: Invalid argument
   stty: standard input: Invalid argument

代码片段:它会在/data/home/user/bin/pushfile.sh /tmp/$ISSUE.$p4Cur $ RUN_ENV |的输出中生成 - > awk'{print“\ t”$ 0}'2>&1> $ tmpLog

#!/bin/ksh
 if [[ $ENV != "production" ]]
 then
    . $HOME/bin/getenv $RUN_ENV >> $RUN_LOGFILE
    if [[ ! -n $FILE_HOME ]]
    then
    echo "FILE_HOME could not be null"
    exit 1
    fi
    cd $FILE_HOME
    cat /tmp/$TICKET.$p4Cur | while read LINE
    do
    p4 sync -f "$LINE" 2>&1 > $tmpLog
            rc=$?
            cat $tmpLog | tee -a $RUN_LOGFILE
            if [[ $rc -gt 0 ]]
            then
            echo "Failed to sync file"
            exit $rc
            fi
    done
 fi

 if [[ $ENV != "production" ]]
 then
     echo "This is FLAG!!!"
    /data/home/user/bin/pushfile.sh /tmp/$ISSUE.$p4Cur $RUN_ENV | awk   '{print "\t" $0}' 2>&1 > $tmpLog

    cat $tmpLog | tee -a $RUN_LOGFILE

    errormsg=`grep "ERROR" $tmpLog `
    erc=$?
    if [[ $erc == 0 ]];then
            echo "Failed to run    /data/home/user/bin/pushfile.sh/tmp/$ISSUE.$p4Cur $BUILD_ENV ! script terminate!" 
            exit 1
    fi

2 回答

  • 0

    也许这可能是解决方案;

    先跑这个;

    stty sane
    

    然后运行你的脚本;

    在男人身上;

    stty changes and prints terminal line settings.
    
    sane   same  as cread -ignbrk brkint -inlcr -igncr icrnl -iutf8 -ixoff -iuclc -ixany imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh
                  -xcase -tostop -echoprt echoctl echoke, all special characters to their default values
    

    如果不工作,你能提供;

    stty -a
    
  • 0

    两个猜测:

    • 代码来源此行包含 $RUN_ENV . 我们不知道那是什么 . Stdout被捕获到 $RUN_LOGFILE ,stderr没有被分离并进入终端 .

    . $HOME/bin/getenv $RUN_ENV >> $RUN_LOGFILE

    • 此构造将所有stderr(fd 2)重定向到屏幕,而正常 p4 (Perforce perchance?)重定向到 $tmpLog

    p4 sync -f "$LINE" 2>& 1 > $tmpLog

    如果要将stdout和stderr捕获到文件中,请切换两个:

    ...... > $tmpLog 2>& 1

    简而言之,有两个命令可以产生任何类型的输出搞乱你的屏幕 . 找出它是什么,并将该输出转移到适当的水槽 .

相关问题