我有一个名为测试文件它位于目录中/home/用户使用以下代码:
#!/bin/bash
echo "Execute command number 1 (bash)"
. /opt/IBM/taddm/dist/bin/control.sh
echo "Execute command number 2 (jython)"
. /opt/IBM/taddm/dist/bin/collect_logs.jy "@g"
运行命令 1 时,我收到以下消息:
./test.sh: line 5: /opt/IBM/taddm/dist/bin/control.sh: No such file or directory
当我转到目的地(/bin)并从那里运行命令时,没有任何问题。
当运行命令 2 时,我收到以下消息:
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 1: Script: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 2: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 2: $'user@XXXXX:~\a\E[?1034h[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 3: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 3: user@XXXXX:/opt/IBM/taddm/dist/log/support[user@XXXXX: No such file or directory
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 4: total: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 5: -rw-r-----.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 5: $'31mTADDM_ISA_Collection.General.20220323140619.zip\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 6: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 6: user@XXXXX:/opt/IBM/taddm/dist/log/support[user@XXXXX: No such file or directory
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 7: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 7: user@XXXXX:/opt/IBM/taddm/dist/log/support[user@XXXXX: No such file or directory
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 8: total: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 9: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 9: user@XXXXX:/opt/IBM/taddm/dist/log/support[user@XXXXX: No such file or directory
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 10: $'\E[3': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 10: $'J\E[H\E[2J\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 10: user@XXXXX:/opt/IBM/taddm/dist/log/support[user@XXXXX: No such file or directory
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 11: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 11: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 12: total: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 13: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 13: $'34m12:35:27\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 14: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 14: $'34m2022\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 15: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 15: $'34m22\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 16: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 16: $'34mCET\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 17: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 17: $'34mMar\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 18: -rwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 18: $'32mmenu.sh\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 19: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 19: $'34mPM\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 20: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 20: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 21: $'\E[3': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 21: $'J\E[H\E[2J\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 21: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 22: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 22: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 23: total: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 24: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 24: $'34m12:35:27\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 25: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 25: $'34m2022\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 26: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 26: $'34m22\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 27: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 27: $'34mCET\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 28: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 28: $'34mMar\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 29: -rwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 29: $'32mmenu.sh\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 30: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 30: $'34mPM\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 31: -rw-rw-r--.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 32: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 32: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 33: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 33: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 34: total: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 35: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 35: $'34m12:35:27\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 36: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 36: $'34m2022\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 37: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 37: $'34m22\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 38: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 38: $'34mCET\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 39: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 39: $'34mMar\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 40: -rwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 40: $'32mmenu.sh\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 41: drwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 41: $'34mPM\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 42: -rwxrwxr-x.: command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 42: $'32mtest.sh\E[0m\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 43: $'\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 43: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 44: $'\E[3': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 44: $'J\E[H\E[2J\E]0': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 44: $'user@XXXXX:~\a[user@XXXXX': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 46: $'\r': command not found
/opt/IBM/taddm/dist/bin/collect_logs.jy: line 51: syntax error near unexpected token `$'do\r''
'opt/IBM/taddm/dist/bin/collect_logs.jy: line 51: `do
当我转到目的地(/bin)并从那里运行命令时,没有任何问题。
我还尝试过不带文件扩展名的命令(/bin/control 和 /bin/collect_logs),并且我尝试使用source
而不是,.
但这也没有帮助。
为什么我不能从我自己的 bash 脚本中运行其他脚本?
谢谢
答案1
如果脚本位于您的 $PATH 中并且它们是可执行的,则意味着您可以通过键入
control.sh
或从任何地方启动它们collect_logs.jy "@g"
你可以这样做
#!/bin/bash
echo "Execute command number 1 (bash)"
control.sh
echo "Execute command number 2 (jython)"
collect_logs.jy "@g"
如果需要指定目录,只需省略点:
#!/bin/bash
echo "Execute command number 1 (bash)"
/opt/IBM/taddm/dist/bin/control.sh
echo "Execute command number 2 (jython)"
/opt/IBM/taddm/dist/bin/collect_logs.jy "@g"
您可能需要首先使它们可执行:
chmod +x /opt/IBM/taddm/dist/bin/control.sh
chmod +x /opt/IBM/taddm/dist/bin/collect_logs.jy