Running.sh scripts en Git bash


Estoy en una máquina Windows usando git 2.7.2.Windows.1 con MINGW64.

Tengo un script en C:/path/to/scripts/myScript.sh

¿Cómo puedo ejecutar este script desde mi git bash?

Fue posible agregarlo al archivo .bashrc y luego simplemente ejecutar todo el archivo bashrc.

Pero quiero agregar el script a un archivo separado y ejecutarlo desde allí.

Author: Michael, 2016-04-04

4 answers

Digamos que tienes un script script.sh. Para ejecutarlo ( usando Git Bash ), debes hacer lo siguiente

chmod +x script.sh
./script.sh

Puede cambiar el chmod a los permisos ejecutables que desee. Esos se pueden encontrar aquí.

Nota: El chmodsolo tiene que ejecutarse una vez. Ejecute ./script.sh cuando desee ejecutar el script.

 23
Author: intboolstring,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-14 03:00:09
#!/usr/bin/env sh

Así es como git bash sabe que un archivo es ejecutable. chmod a+x no hace nada en gitbash.

 20
Author: 18446744073709551615,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-03 11:42:06

Si desea ejecutar un archivo de script desde el indicador git bash en Windows, simplemente preceda el archivo de script con sh

sh my_awesome_script.sh
 16
Author: JohnWrensby,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-09 08:00:48

Tuve un problema similar, pero estaba recibiendo un mensaje de error

No se puede ejecutar el archivo binario

Descubrí que el nombre del archivo contenía caracteres no ASCII. Cuando se arreglaron, el script funcionó bien con ./script.sh.

 2
Author: Mike,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-16 04:30:52