如何在bash函数中打印换行符
发布时间:2020-12-15 21:14:24 所属栏目:安全 来源:网络整理
导读:我在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
我在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空字符串命令(echo“”)似乎不起作用.相反,函数外的相同命令似乎工作正常.如何在bash函数中打印空换行? 解决方法
你在反引号(或$())中放入的内容会将换行符转换为空格.您可以直接调用该函数,而不是在反引号中使用它.
换句话说,该函数实际上生成了空行,但是当你在最终的echo中使用它时,带有$()的反引号过程会将它们转换为空格. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |