Android-student
@Android-student

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

VSCodeのターミナルからシェルスクリプトを実行した際の結果を確認したい。

解決したこと

VSCodeのターミナルからシェルスクリプトを実行した際の結果を確認したい。

発生している問題・エラー

VSCodeのターミナルからシェルスクリプトを実行しても何も表示されない。testを表示したい。

PS C:\test\employee\script> .\shlscript.sh
PS C:\test\employee\script>
                            ./shlscript.sh
PS C:\test\employee\script>

PS C:\test\employee\script> ls


    ディレクトリ: C:\test\employee\script


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        2025/03/11      7:03                DDL
d-----        2025/03/11      7:04                DML
-a----        2025/03/21      5:45           1675 init.sh
-a----        2025/03/21      5:50             24 shlscript.sh


PS C:\test\employee\script> 

該当するソースコード

shlscript.sh
#!/bin/bash

echo "test"

環境

vscodeの拡張機能として下記はインストール済です。
・Remote Development
・Bash IDE
・shellcheck

0

2Answer

プロンプトの頭が「PS」となっているのでWindowsのPowerShellで実行しようとしてるからではないでしょうか?
Bashのシェルを実行したいのであれば、Linuxが実行している環境(別のホスト or ローカルのwsl内でのLinux)に接続して実行すれば良いと思います。
VS Codeでリモート接続する方法は他の記事にいっぱいあるので探してみてください。

0Like

Comments

  1. PowerShellのコマンドを実行したい場合は、拡張子を.psにしましょう

Your answer might help someone💌