简体   繁体   English

我无法从“ script1.sh”运行“ script2.sh”(它们位于同一文件夹中并具有755权限)

[英]I can't run 'script2.sh' from 'script1.sh' (they are in the same folder and have 755 permission)

I have a dumb question and I hope you can help me .. I have "script1.sh" and "script2.sh", both have permissions 755 and are in the same folder 我有一个愚蠢的问题,希望您能为我提供帮助。.我有“ script1.sh”和“ script2.sh”,两者的权限均为755,并且位于同一文件夹中

script1.sh: script1.sh:

#!/bin/bash
zenity --info --text="SCRIPT1.sh"
./script2.sh
exit 0

script2.sh: script2.sh:

#!/bin/bash
zenity --info --text="TEST SCRIPT2.SH "
exit 0

Make a cd to the folder containing the scripts, then (from the bash console) write: 将CD放入包含脚本的文件夹中,然后(从bash控制台)编写:

./script1.sh

It runs all OK! 一切正常! ..the show 2 posts zenity ..show 2赞

---------------------------------------- ----------------------------------------

But the problem is here ... 但是问题在这里...

If I create a shortcut 'gnome' (All Settings> Shortcuts> Keyboard) and income as /path/to/script1.sh command .. only the first message zenity is shown (script1.sh) 如果我创建快捷方式“ gnome”(“所有设置”>“快捷方式”>“键盘”)并将收入作为/path/to/script1.sh命令..仅显示第一个消息“ zenity”(script1.sh)

It means that fails to run 'script2.sh' from 'script1.sh' when pressure key combination... why? 这意味着在按组合键时无法从“ script1.sh”运行“ script2.sh” ...为什么? How could solve this problem? 如何解决这个问题?

Thanks you! 谢谢!

This will only work when you run script1.sh from the same directory script2.sh is in, since ./script2.sh says run script2 from the current directory. 当您运行这只会工作script1.sh从同一目录script2.sh是因为, ./script2.sh说从当前目录运行SCRIPT2。

You can either set your PATH to include the directory containing the scripts, omitting ./ or put in the absolute pathname for script2.sh . 您可以将PATH设置为包含包含脚本的目录,而忽略./或者将其放置在script2.sh的绝对路径中。

When you created the shortcut, it is only running your first script because you specified /path/to/script1.sh , and since the second script is not located in your current working directory, it fails to find the file. 创建快捷方式时,它仅运行第一个脚本,因为您指定了/path/to/script1.sh ,并且由于第二个脚本不在当前工作目录中,因此无法找到该文件。 If I were you, I would rewrite your first script to... 如果我是你,我会将您的第一个脚本重写为...

#!/bin/bash
zenity --info --text="SCRIPT1.sh"
/PATH/TO/SCRIPT/script2.sh
exit 0

You could add some logic to either search your filesysystem for the file to retrieve location information, or you could simply modify $PATH to include that location. 您可以添加一些逻辑以在文件系统中搜索文件以检索位置信息,或者可以简单地修改$ PATH以包括该位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM