日期:2014-05-16  浏览次数:20944 次

shell中echo最后面加入\c,还是存在回车换行现象
代码是实现copy功能,增加在执行cp的时候判断目标地址是否存在
then
  echo "usage:mycp from to"
  exit 1
fi

from=$1
to=$2
if [ -e $to ]
then
  echo "$to already exist ;overwrite(yes/no)?\c"
  read answer
  if [ $answer != yes ]
  then
  echo "copy not performed"
  exit 0
  fi
fi
cp $from $to





执行后,现象是echo后面的\c不生效,每次执行是还有回车换行
 ./mycp.sh test te
te already exist ;overwrite(yes/no)?\c

请教下这个是什么原因?如何解决

------解决方案--------------------
echo -e "$to already exist ;overwrite(yes/no)?\c"
------解决方案--------------------
另外一个方法!
直接echo -n 就不会换行
------解决方案--------------------
read -p "提示信息" answer
------解决方案--------------------
C/C++ code
echo -e '\n'
 echo -n