почему xterm не работает с моим скриптом?

312
phong

мой сценарий: echo 123456 > /folder/folder/123.txt

Я запустил скрипт с помощью xterm: xterm -e my.sh &

Не работает

0
Что такое вывод / ошибка // что происходит? mstruebing 8 лет назад 0
на самом деле, ничего не произошло или не было сообщено. Это просто не сработало. phong 8 лет назад 0

2 ответа на вопрос

1
Argonauts

There is one major issue and possibly one minor issue with your xterm call. First - You don't want the & to background the script - it is very likely doing exactly what you asked it to do and runs in the background (effectively invisible - you can see it with ps or jobs in the shell that you launched it from; ps -A from anywhere, etc.).

My read of your situation is that you are trying to spawn a new xterm instance and have this script execute in it; and it will do not that in the background (at least visibly).

Second, you should provide the full path to my_script.sh, use it's full path, and enclose the argument to the -e flag entirely in quotes, e.g. "/home/you/my_script.sh"

That may not be causing you an issue here; I'm not positive. It will cause you an issue at some point if you write similar scripts in the future, as without quotes you could be the victim of inadvertent bash expansion.

Last note - when calling a bash script from a bash shell, the #!/bin/bash is actually completely unnecessary. It's good habit, and it makes it more portable - someone else will jump on this and say '#!/usr/bin/env bash is MORE portable',and yes, it is. But you don't need either for it to work, assuming you call the script from bash (but you should always have it anyways).

Спасибо. Предоставляя полный путь к сценарию, он работает. phong 8 лет назад 0
0
torchhound

Make sure that your script begins with a shebang in the form:

#!/bin/bash #(or #!/bin/sh for POSIX compliance) 

Next make sure that you have made your script executable by running:

$ chmod +x my_script.sh 

Finally try and run your script:

$ ./my_script.sh 

Keep in mind that xterm is a graphical terminal emulator not Bash itself.

Я сделал все это, скрипт работает в bash, но не с xterm. phong 8 лет назад 0
Вы пробовали все эти шаги в xterm и ничего не произошло? Вы получили ошибку? torchhound 8 лет назад 0
конечно, он безупречно работал внутри xterm, но не запускался при запуске из оболочки bash. phong 8 лет назад 0

Похожие вопросы