我在一个bash脚本文件中有以下代码:
#! /bin/sh
#
# Usage:
#
# f.sh <start_directory> <destination_directory> <prepare_directory> <remote_host_for_copy> <remote_user>
#
print_correct_syntax() {
echo "f.sh <start_directory> <destination_directory> <prepare_directory> <remote_host_for_copy> <remote_user>"
echo ""
echo '<start_directory> needs to be a full path, <destination_directory> needs to be full path, <prepare_directory> has to be relative to start_directory path'
echo ""
}
# ---- end of function definition ----
# check number of run-time arguments given to script
if [ $# != 5 ]
then
echo Wrong Syntax! $(print_correct_syntax)
exit;
fi
#---------------------------------------------------
函数(print_correct_syntax)内的回显空字符串命令(echo "")似乎无效。相反,同样的命令在函数外部似乎可以正常工作。如何从bash函数内打印一个空的新行?
echo -n 语法错误! print_correct_syntax
- p.matsinopoulosecho -n '语法错误!' ; print_correct_syntax
。 - Diego Sevilla