Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Bashスクリプトで、特定のフォルダーでコマンドを実行することは可能ですか?たとえば、スクリプトがどのディレクトリに保存されているかに関係なく、/homeを使用してフォルダの内容を印刷するスクリプトを作成したいと思います。ls
/home
ls
実際には、スクリプト内のディレクトリを変更するために使用できますcd(ただし、親シェルには影響しません)。試す
cd
#!/bin/bash # myscript.sh cd /home pwd ls
現在のディレクトリ(である/home)を出力し、その内容を一覧表示します。どこにいてmyscript.shも。
myscript.sh