0
我正在學習在終端中編寫shell腳本。我試圖自動化npm init進程,只是爲了練習。所以我從終端讀入所有參數,然後嘗試自動執行一個npm init
與他們。然而,當npm init
要求入口點時,該過程總是中止。其他任何地方,只要留下一個空行來模擬一個輸入鍵按下,或使用該變量工作正常。爲什麼在那個時候退出?Shell腳本輸入不適用於npm init
read -p "Project name: " name;
read -p "Version: " version;
read -p "Project description: " description;
read -p "Entry point: " entryPoint;
read -p "Test command: " testCommand;
read -p "Git repository: " gitRepo;
read -p "Keywords: " keywords;
read -p "Author: " author;
read -p "License: " license;
read -p "Is this okay?: " isOkay;
npm init <<!
$name
$version
$description
$entryPoint
$testCommand
$gitRepo
$author
$license
$isOkay
!
運行腳本時
端子輸入和結果:
Project name: name
Version: 1.0.0
Project description: description
Entry point: app.js
Test command:
Git repository:
Keywords:
Author: Author
License: ISC
Is this okay?: yes
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (node) name
version: (1.0.0) 1.0.0
description: description
entry point: (index.js)
就是這樣。它每次都在入口點退出。
有趣。這工作 - 謝謝。 ''spawn npm init'後面有大約10秒的延遲。任何想法爲什麼? – cweber105