質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.32%
シェル

シェル(shell)はUnix や Linux 系のOSで使用されるコマンドインタプリタを指します。

Q&A

解決済

1回答

175閲覧

シェルで xdotool を使って press enter を自動化したいがうまくいかない

DeepRoastBeans

総合スコア85

シェル

シェル(shell)はUnix や Linux 系のOSで使用されるコマンドインタプリタを指します。

1グッド

0クリップ

投稿2025/02/23 14:33

実現したいこと

ubuntu22.04にrustなどをインストールするのをシェルを使って自動化したい

発生している問題・分からないこと

xdotool key Return | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
と書いても、press enterが自動化できず、以下のように表示されてしまう。

// 省略
default host triple: x86_64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes

  1. Proceed with standard installation (default - just press enter)
  2. Customize installation
  3. Cancel installation

該当のソースコード

shell

1cd $home 2yes | sudo apt-get update 3yes | sudo apt-get upgrade 4yes | sudo apt-get install libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang cmake make libprotobuf-dev protobuf-compiler xdotool 5xdotool key Return | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 6source $HOME/.cargo/env 7rustup update 8cargo --version 9rustc -V

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

xdotool key KP_Enter | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
としたり、curlの次の行に書いたりしてみたが、うまくいかない。

補足

特になし

melian👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

melian

2025/02/23 14:57

https://sh.rustup.rs の中身を確認してみると、-y オプションでプロンプトを無効にすることができます。("Proceed with standard installation" を選択するのと同じで、すべてデフォルトの設定でインストールが進みます) Options:  -y   Disable confirmation prompt. なので、bash(1) の -s オプションを利用して、上記の -y オプションを渡すとよいかと思います。  -s   If the -s option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell or when reading input through a pipe. $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | /bin/bash -s -- -y
DeepRoastBeans

2025/02/23 15:50

頂いた内容で解決しました!大変ありがとうございます!!!
guest

回答1

0

ベストアンサー

xdotool って、GUI用のツールではないのでしょうか?

案1:そういう目的のために作られたexpectコマンドを使う(expectは初めての人にはちょっとわかりにくいかも)
案2:あらかじめhttps://sh.rustup.rsをダウンロードして、応答不要に書き換えた物を使う

投稿2025/02/23 14:50

otn

総合スコア86208

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

DeepRoastBeans

2025/02/23 15:52

ありがとうございます! expectの書き方に苦戦していますが試してみます!!
otn

2025/02/27 15:57

案2が可能ならそっちの方が、おそらく楽です。 「https://sh.rustup.rs の中味が頻繁に書き換わり、常に最新版を実行したい」場合は駄目ですが。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.32%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問