bash - Running script existing in another folder - paths -


मेरे पास तीन स्क्रिप्ट हैं:

  - bin ------ start Sh - स्क्रिप्ट ------ निर्देशिका_आ ------------ निर्देशिका_ब ------------------ स्क्रिप्ट_1.sh ----- ------------- स्क्रिप्ट_2.sh   

start.sh चलाता है script_1.sh , और फिर script_1.sh चलाता है script_2.sh

समस्या पथों के साथ है:

start.sh: < / strong>

  पथ_to_script = "../scripts / directory_a / directory_b / script_1.sh"; कमांड = "$ path_to_script param1 param2"; परिणाम = `$ command`;   

script_1.sh: <पूर्व> path_to_script = "। / Script_2.sh"; कमांड = "$ path_to_script param1 param2"; परिणाम = `$ command`;

समस्या यह है कि script_1.sh गलत निर्देशिका में script_2.sh की तलाश कर रही है: / bin / script_2 Sh

मैं इसे इस तरह पूर्ण पथ से गुजारने से ठीक नहीं करना चाहूंगा (क्योंकि 'directory_a' नाम बदल सकता है):

script_1.sh: <पूर्व> path_to_script = "../ स्क्रिप्ट / निर्देशिका_अ / निर्देशिका_ब / स्क्रिप्ट_2.sh"; कमांड = "$ path_to_script param1 param2"; परिणाम = `$ command`;

सामान्य.श

basedir = < P> पर स्क्रिप्ट start.sh करें:

  basedir = $ (dirname $ 0) pushd $ basedir absoluteBasedir = $ (पीडब्ल्यूडी) popd export absoluteBasedir स्क्रिप्ट 1 = $ (absolbB) / scripts / directory_a / directory_b /script1.sh   

स्क्रिप्ट 1:
  अगर [[-z $ absoluteBasedir]] तो पुशड ../../../ absoluteBasedir = $ (पीडब्ल्यूडी) पॉपड एंड स्क्रिप्ट 2 = $ (पूर्णबैजिर) / स्क्रिप्ट / डायरेक्टरी / ए / डायरेक्टरी / बी / एसक्रिप्ट 2। एसआई   

सब किया गया है;)

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -