简体   繁体   中英

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:

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

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:

./script1.sh

It runs all OK! ..the show 2 posts zenity

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

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)

It means that fails to run 'script2.sh' from 'script1.sh' when pressure key combination... why? 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.

You can either set your PATH to include the directory containing the scripts, omitting ./ or put in the absolute pathname for 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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