क्यों स्रोत एक त्रुटि देता है "बाइनरी फ़ाइल निष्पादित नहीं कर सकता"


10

मेरे पास एक छोटी फ़ाइल है जो एक tmuxसत्र को प्रारंभ करती है और फिर कुछ विंडो बनाती है। कुछ डिबगिंग और ट्विकिंग के बाद चीजों ने ठीक काम किया जब तक कि मैंने टेक्स्ट फाइल को ( tmuxकमांड्स के साथ ) से नया नाम नहीं spamदिया xset:

$ source xset
bash: source: /usr/bin/xset: cannot execute binary file

मैंने अब फ़ाइल को वापस नाम दिया है और source spamफिर से काम करता है, लेकिन मैं सोच रहा हूं कि यह क्यों है। फ़ाइल मेरे होम डायरेक्टरी में है, और इसमें नहीं /usr/bin


एक बाइनरी कहा जाता है xset। कोशिश करो source ./xset
फहीम मीठा

जवाबों:


11

bashआंतरिक आदेश स्रोत, पहले, पथ में फ़ाइल नाम के लिए लग रहा है जब तक कि वहाँ एक स्लैश (है /) फ़ाइल नाम में। xsetआपके PATH में एक निष्पादन योग्य फ़ाइल है, इसलिए समस्या है।

आप या तो source ./xsetस्रोतपाठ के विकल्प को निष्पादित या बदल सकते हैं :

shopt -u sourcepath

से bashमानव पेज:

      source filename [arguments]
          Read and execute commands from filename  in  the  current  shell
          environment  and return the exit status of the last command exe
          cuted from filename.  If filename does not contain a slash, file
          names  in  PATH  are used to find the directory containing file
          name.  The file searched for in PATH  need  not  be  executable.
          When  bash  is  not  in  posix  mode,  the  current directory is
          searched if no file is found in PATH.  If the sourcepath  option
          to  the  shopt  builtin  command  is turned off, the PATH is not
          searched.  If any arguments are supplied, they become the  posi
          tional  parameters  when  filename  is  executed.  Otherwise the
          positional parameters are unchanged.  The return status  is  the
          status  of  the  last  command exited within the script (0 if no
          commands are executed), and false if filename is  not  found  or
          cannot be read.

5

sourceआदेश होगा :

वर्तमान शेल संदर्भ में फ़ाइल नाम तर्क से आदेशों को पढ़ें और निष्पादित करें । यदि फ़ाइल नाम में स्लैश नहीं है, तो फ़ाइल नामPATH खोजने के लिए चर का उपयोग किया जाता है ।

यह व्यवहार POSIX द्वारा परिभाषित (के लिए ., इसके उपनाम) है । क्यों? ठीक है, आप खट्टे विन्यास स्क्रिप्ट को अंदर रख सकते हैं PATHऔर उन्हें एक योग्य पथ के बिना एक्सेस कर सकते हैं। अपनी इच्छित फ़ाइल तक पहुँचने के लिए, इसके बजाय एक पूर्ण या सापेक्ष पथ दें:

source ./xset
source ~/xset
source /home/shawn/xset

उपरोक्त सभी काम करेंगे जैसा कि आपको शुरू में उम्मीद थी। तुम भी निष्क्रिय कर सकते हैं sourcepathके साथ shopt

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.