
text.sh
次の単純なbashスクリプトがあります。
#!/bin/bash
read username
read password
echo "script attempted with $username $password"
私はそれをそう呼びたいです:
[[email protected] root]# ./test.sh bing s3cr3t
そしてエコーをさせてください:
script attempted with bing s3cr3t
<<<
印刷に使用できますが、bing
同時に両方を使用することはできません。明らかに単純ですが、どのキーワードを検索するのかわからないため、Googleの機能は失敗します。
答え1
必要なのは、標準入力から読むのではなく、コマンドライン引数にアクセスすることです。正しい方法でスクリプト:
#!/bin/bash
username="$1"
password="$2"
echo "script attempted with $username $password"
特殊変数$1
などの$2
最初、2番目などを含みます。実行中のコマンドラインに渡された引数。より多くの情報を提供するここ、そして他の多くの場所。