在脚本中使用set命令调试脚本

  当脚本文件较长时,可以使用set命令指定调试一段脚本。在脚本中使用set -x命令开启调式模式;使用set +x命令关闭调式模式。

例如:

#!/bin/bash

#Scriptname: greetings.sh

echo -e "Hello $LOGNAME, \c"

echo "it's nice talking to you."

echo -n "Your present working directory is: " $(pwd)

set -x          #######开启调试模式(调试结束可注释此行)####

read -p "What is your name?"    name

echo "Hello $name"

set +x       #######关闭调试模式(调试结束可注释此行)####

echo -e "The time is 'date+%T'!. \nBye"

echo

猜你喜欢

转载自www.cnblogs.com/leo2li/p/8952113.html