简体   繁体   English

如果命令超过 1 行,如何在 shell 或 bash 中输入新行/移动到下一行而不执行命令?

[英]How do I enter a new line/move to the next line without executing command while in a shell or bash if the command has more than 1 line?

so i'm trying to follow a tutorial on creating an Azure VM and the entire tutorial is from the CLI.所以我正在尝试按照有关创建 Azure VM 的教程进行操作,整个教程来自 CLI。 It is specifically using bash.它专门使用bash。 I know next to nothing about using CLI so it is pretty intimdating.我对使用 CLI 几乎一无所知,所以这很吓人。 Anyways all the commands look like this in the tutorial:无论如何,教程中的所有命令都如下所示:

az vm create \
  --resource-group myResourceGroup \
  --name myVM \
  --image UbuntuLTS \
  --admin-username azureuser \
  --generate-ssh-keys

But when I try to make a new line and go to that new line to enter in the argument/parameter it keeps trying to execute the command and i cant execute anything since obviously what im typing in is missing parameters:但是,当我尝试创建一个新行并将 go 插入到该新行以输入参数/参数时,它一直在尝试执行命令并且我无法执行任何操作,因为显然我输入的是缺少参数:

az vm create \ --resource-group ShahVMAzureUB \ --name ShahVM \ --imageUbuntuLTS \ --admin-username shahjacob \ --generate-ssh-keysaz vm create
: error: the following arguments are required: --name/-n, --resource-group/-g

Quoteth the man page引用手册页

If a \<newline> pair appears, and the backslash is not itself quoted, the \<newline> is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).如果出现了\<newline>对,并且反斜杠本身没有被引用,则\<newline>被视为续行(也就是说,它从输入 stream 中删除并被有效地忽略)。

So, you literally need a newline (press ENTER ) after you type the \ to tell the shell you want to enter more parameters but on a separate line.因此,在您键入\告诉 shell 您想要输入更多参数但在单独的行上之后,您实际上需要一个换行符(按ENTER )。

Generally this is used for print (or even Stackoverflow answers) so you don't have one mega-line that's hard to grok.通常,这用于打印(甚至 Stackoverflow 答案),因此您没有难以理解的巨型行。 If you want it all on one line, remove the \ between the parameters.如果您希望全部放在一行上,请删除参数之间的\

To expand on SiegeX's answer (since I don't have enough rep to comment...)扩展 SiegeX 的答案(因为我没有足够的代表发表评论......)

az vm create \ 
  --resource-group myResourceGroup \
  --name myVM \
  --image UbuntuLTS \
  --admin-username azureuser \
  --generate-ssh-keys

is functionally equivalent to在功能上等同于

az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys

For printing the ENTER in cmd we have to use the echo.为了在 cmd 中打印 ENTER,我们必须使用回显。 command instead of echo "\n" or echo '\n'命令而不是echo "\n" 或 echo '\n'

Use backtick -(key to the left of q ~ (tilde) and )使用反引号-(key to the left of q ~ (tilde) and

and not the '- Apostrophe or single quote.而不是 '- 撇号或单引号。

Just need to use a backtick ` instead of the \

Your code should look like this:

az vm create ` 
  --resource-group myResourceGroup `
  --name myVM `
  --image UbuntuLTS `
  --admin-username azureuser `
  --generate-ssh-keys

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何进入postgres bash命令行并使用shell脚本退出? - How can I Enter into postgres bash command line and exit using shell script? 如何在 Linux 的命令行中打开一个新的 window(shell)? - How do I open a new window (shell) from command line in Linux? 如何在bash中以root身份在命令行上运行for循环 - How do I run a for loop on the command line as root in bash 如何在Bash命令行中生成ASCII代码2和3? - How do I generate ASCII codes 2 and 3 in a Bash command line? 执行包含重定向字符的bash行(命令) - Executing bash line(command) that contains redirection characters BASH Shell 命名命令行 arguments - BASH Shell named command line arguments Shell:如何设置一个执行命令的工作目录而不影响一行中的其他命令 - Shell: How to set the working directory for one executing command without affect other commands in a line 如何在bash脚本的循环中引用“下一个”命令行参数? - How to reference the “next” command line argument in a bash script for loop? 如何在命令行上调用python脚本,就像调用普通的shell命令(如cp)一样? - How do I call a python script on the command line like I would call a common shell command, such as cp? 用于输入多个目录并执行命令的命令行bash - Command line bash for entering multiple directories and executing a command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM