Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么echo和print命令会在shell脚本中生成箭头符号(->;)?_Shell_Ksh - Fatal编程技术网

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

为什么echo和print命令会在shell脚本中生成箭头符号(->;)?,shell,ksh,Shell,Ksh,运行ksh脚本时有点棘手,其中有“echo”和“print”命令。并且输出包含箭头符号->。比如: -> % Total % Received % Xferd Average Speed Time Time Time Current -> Dload Upload Total Spent Left Speed -> 0 4374 0 0

运行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

也许这就是解决方案

先跑这个,

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
两种猜测:

  • 代码来源于包含
    $RUN\u ENV
    的此行。我们不知道是什么 就是。Stdout被捕获到
    $RUN_LOGFILE
    ,stderr未被指定并转到终端

    $HOME/bin/getenv$RUN\u ENV>>$RUN\u日志文件

  • 此构造将所有stderr(fd2)重定向到屏幕,并将正常的
    p4
    (Perforce-percentance?)重定向到
    $tmpLog

    p4同步-f“$LINE”2>&1>$tmpLog

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

    <代码>>$tmpLog 2>&1

  • 简而言之,有两个命令可以产生任何类型的输出,扰乱屏幕。
    找出它是哪一个,并将输出转移到适当的接收器。

    您能提供您的ksh脚本吗?也许您是在后台启动脚本,然后按Enter a view times等待输出。当您的命令提示看起来像
    ->
    时,此提示可以与脚本的输出混合使用。@Mustafa,谢谢您的回复。我只是在出现问题的地方附加一些脚本片段。