

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 中啟用和使用命令提示字元 AWS CLI
<a name="cli-usage-parameters-prompting"></a>

您可以在執行 命令時，讓 第 2 AWS CLI 版提示您命令、參數和資源`aws`。

**Topics**
+ [

## 運作方式
](#cli-usage-auto-prompt-about)
+ [

## 自動提示功能
](#cli-usage-auto-prompt-features)
+ [

## 自動提示模式
](#cli-usage-auto-prompt-modes)
+ [

## 設定自動提示
](#cli-usage-auto-prompt-configure)

## 運作方式
<a name="cli-usage-auto-prompt-about"></a>

啟用自動提示後，您可使用 **ENTER** 鍵來完成部分輸入的命令。按下 **ENTER** 鍵後，系統會根據您繼續輸入的內容來建議命令、參數和資源。建議會在左側列出命令、參數或資源的名稱，並在右側列出相關描述。若要選取並使用建議，請使用方向鍵來反白顯示該列，然後按下 **SPACE** 鍵。完成輸入命令後，按下 **ENTER** 來使用命令。以下範例呈現自動提示的建議清單。

```
$ aws
> aws a
       accessanalyzer                Access Analyzer
       acm                           AWS Certificate Manager
       acm-pca                       AWS Certificate Manager Private Certificate Authority
       alexaforbusiness              Alexa For Business
       amplify                       AWS Amplify
```

## 自動提示功能
<a name="cli-usage-auto-prompt-features"></a>

自動提示包含以下實用功能：

**文件面板**  
提供有關目前命令的說明文件。若要開啟文件，請按 **F3** 鍵。

**命令完成**  
建議可使用的 `aws` 命令。若要查看清單，請輸入命令的部分內容。以下範例是搜尋以字母 `a` 為開頭的服務。  

```
$ aws
> aws a
       accessanalyzer                Access Analyzer
       acm                           AWS Certificate Manager
       acm-pca                       AWS Certificate Manager Private Certificate Authority
       alexaforbusiness              Alexa For Business
       amplify                       AWS Amplify
```

**參數完成**  
您輸入命令後，自動提示功能會開始建議參數。參數的描述包括數值類型，以及有關參數內容的描述。首先會列出必要的參數，再按要求進行標記。以下範例顯示 `aws dynamodb describe-table` 的參數自動提示清單。  

```
$ aws dynamodb describe-table
> aws dynamodb describe-table 
                              --table-name (required)  [string] The name of the table to describe.
                               --cli-input-json         [string] Reads arguments from the JSON string provided. The JSON string follows the format provide...
                               --cli-input-yaml         [string] Reads arguments from the YAML string provided. The YAML string follows the format provide...
                               --generate-cli-skeleton  [string] Prints a JSON skeleton to standard output without sending an API request. If provided wit...
```

**資源完成**  
自動提示會使用可用的 AWS 資源屬性呼叫 AWS API 以建議資源數值。此會允許在輸入參數時，自動提示建議您擁有的潛在資源。在以下範例中，自動提示在您填入 `aws dynamodb describe-table` 命令的 `--table-name` 參數時列出表格名稱。  

```
$ aws dynamodb describe-table
> aws dynamodb describe-table --table-name 
                                            Table1
                                            Table2
                                            Table3
```

**速記完成**  
若為使用速記語法的參數，自動提示會建議要使用的數值。在下列範例中，自動提示會列出 `aws ec2 run-instances` 命令中 `--placement` 參數的速記語法數值。  

```
$ aws ec2 run-instances
> aws ec2 run-instances --placement 
 AvailabilityZone=      [string] The Availability Zone of the instance. If not specified, an Availability Zone wil...
 Affinity=              [string] The affinity setting for the instance on the Dedicated Host. This parameter is no...
 GroupName=             [string] The name of the placement group the instance is in.
 PartitionNumber=       [integer] The number of the partition the instance is in. Valid only if the placement grou...
```

**檔案完成**  
在 `aws` 命令中填入參數時，自動完成會在使用前綴 `file://` 或 `fileb://` 後建議本機檔案名稱。在以下範例中，在為 `aws ec2 run-instances` 命令輸入 `--item file://` 後，自動提示建議本機檔案。  

```
$ aws ec2 run-instances
> aws ec2 run-instances --item file:// 
                         item1.txt
                         file1.json
                         file2.json
```

**區域完成**  
在使用全域參數 `--region` 時，自動提示會列出可供選取的區域。下列範例示範為 `aws dynamodb list-tables` 命令輸入 `--region` 後，自動提示會建議以字母排序的區域。  

```
$ aws dynamodb list-tables
> aws dynamodb list-tables --region 
                                     af-south-1
                                     ap-east-1
                                     ap-northeast-1
                                     ap-northeast-2
```

**設定檔完成**  
在使用全域參數 `--profile` 時，自動提示會列出您的設定檔。下列範例示範為 `aws dynamodb list-tables` 命令輸入 `--profile` 後，自動提示會建議您的設定檔。  

```
$ aws dynamodb list-tables
> aws dynamodb list-tables --profile 
                                     profile1
                                     profile2
                                     profile3
```

**模糊搜尋**  
完成包含特定字元集的完整命令和數值。下列範例示範為 `eu` 命令輸入 `--region eu` 後，自動提示會建議包含 `aws dynamodb list-tables` 的區域。  

```
$ aws dynamodb list-tables
> aws dynamodb list-tables --region west
                                         eu-west-1
                                         eu-west-2
                                         eu-west-3
                                         us-west-1
```

**歷程記錄**  
若要在自動提示模式中檢視並執行先前使用的命令，請按 **CTRL \$1 R**。歷史記錄會列出先前用過的命令，您可以使用方向鍵進行選取。以下範例顯示自動提示模式中的歷史記錄。  

```
$ aws
> aws 
        dynamodb list-tables
        s3 ls
```

## 自動提示模式
<a name="cli-usage-auto-prompt-modes"></a>

第 2 AWS CLI 版的自動提示有 2 種可設定的模式：
+ **完整模式**：無論您使用 `--cli-auto-prompt` 參數手動呼叫或永久啟用命令，每次嘗試執行 `aws` 命令時都會使用自動提示。這包括在完整的命令或不完整的命令之後按下 **ENTER**。
+ **部分模式：**如果命令不完整或因用戶端驗證錯誤而無法執行時，使用自動提示。如果您有預先存在的指令碼、Runbook，或是您只希望系統自動提示您不熟悉的命令 (而非針對每個命令發出提示)，這個模式就特別有用。

## 設定自動提示
<a name="cli-usage-auto-prompt-configure"></a>

若要設定自動提示，您可以依優先順序使用下列方法：
+ **命令列選項**可用於啟用或停用單一命令的自動提示。使用 `--cli-auto-prompt` 可呼叫自動提示，使用 `--no-cli-auto-prompt` 則能停用自動提示。
+ **環境變數**使用 `aws\$1cli\$1auto\$1prompt` 變數。
+ **共享組態檔**使用 `cli\$1auto\$1prompt` 設定。