BashスクリプトUbuntuでアプリケーションを呼び出す

BashスクリプトUbuntuでアプリケーションを呼び出す

私のUbuntuコンピュータに特定のアプリケーションがインストールされていて、これをbashスクリプトで使用しよ/usr/local/MYPROGRAM/bin/myappうとするとコマンドが見つからないというエラーが発生しますが、通常のターミナルウィンドウで呼び出すと正常に動作します。ファイルがありますが、bashスクリプトから呼び出す方法を知りたいです。myfnmybashscript.shmyfnmyfn~/.bashrcmyfnmybashscript.sh

これはmybashscript.sh

#!/bin/bash -i

alias brc='source ~/.bashrc'

source /usr/local/MYPROGRAM/bin/myapp
#exec bash
echo "******************pathhhhhhhh************"
echo $PATH
echo "******************pathhhhhhhh************"
/usr/local/MYPROGRAM/bin/myapp

私が実行したときの出力は次のとおりです./mybashscript.sh

bash: /bin/realbin/myapp: No such file or directory
******************pathhhhhhhh************
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
******************pathhhhhhhh************
/usr/local/MYPROGRAM/bin/myapp: 3: /usr/local/MYPROGRAM/bin/myapp: /bin/realbin/myapp: not found

ベストアンサー1

sourceスクリプトに関数をロードする場合:

source /usr/local/MYPROGRAM/bin/myapp

すべてのサブシェル(スクリプトなど)で関数をグローバルに使用できるようにするには、を使用しますexport。あなたの場合、このコマンドはの関数定義に従います~/.bashrc

export -f myfn

編集:ここで報告された問題が発生しました。

bash: /bin/realbin/myapp: No such file or directory

ファイルが/bin/realbin/myapp存在しないためです。

おすすめ記事