Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run zsh script in specified folder

Tags:

zsh

How to run zsh script in specified folder? How to specify a folder to run a script:

zsh script_name.sh

Documents said that: "-s Force shell to read commands from the standard input. If the -s flag is not present and an argument is given, the first argument is taken to be the pathname of a script to execute." but it does not work.

What is the difference between zsh -c ~/path1/ script1.sh (2 parameters) and zsh -c ~/path1/script1.sh?

like image 335
egor7 Avatar asked Jun 01 '12 16:06

egor7


2 Answers

You should just open a subshell, Execute the following from zsh or bash (including the parentheses):

(cd ~/path1 && source script1.sh)

Note: If your script is written for zsh, name it script1.zsh instead, since zsh syntax is not retro-compatible with old sh's.

like image 195
cruizh Avatar answered Sep 28 '22 22:09

cruizh


This should work:

zsh -c "cd ~/path1 && ./script_name.sh"
like image 33
Stefan Avatar answered Sep 28 '22 23:09

Stefan