問題 ccnp-350-601-topic-1-question-471-v-1cb60df5・第2版

問題

NexusのGuest Shellから、Ethernet1/1~Ethernet1/5のdescriptionをそれぞれServer1~Server5へ設定する。実行するcommandはどれか。

  1. A 
    for x in {1..5}; dohost "conf t ; interface eth1/$x ; description Server$x";
    
  2. B 
    for x in {1..5}; do dohost "conf t ; interface eth1/$x ; description Server$x"; done
    
  3. C 
    for x in (1..5); do dohost "conf t"; "interface eth1/$x"; "description Server$x"; done
    
  4. D 
    for x in (1..5); dohost "conf t ; interface eth1/$x ; description Server$x";
    

正解:B

理由

Bashのfor loopはdoとdoneで処理を囲む。{1..5}で1~5を展開し、各回でdohostへNX-OSの設定commandを渡す。

選択肢ごとの説明

A.
for x in {1..5}; dohost "conf t ; interface eth1/$x ; description Server$x";

Loop本体を開始するdoと終了するdoneがない。Dohostはutility名であり、doの予約語を代用しない。

B.
for x in {1..5}; do dohost "conf t ; interface eth1/$x ; description Server$x"; done

各xを展開し、NX-OS設定commandを一つの文字列としてdohostに渡す。

C.
for x in (1..5); do dohost "conf t"; "interface eth1/$x"; "description Server$x"; done

Bashのrange展開は{1..5}である。Interface/descriptionもdohostへ渡さず、shell commandとして実行しようとしている。

D.
for x in (1..5); dohost "conf t ; interface eth1/$x ; description Server$x";

Rangeの括弧が異なり、do/doneもない。

参考資料

お問い合わせ

演習する →