Note that there are some explanatory texts on larger screens.

plurals
  1. POreplace first line of files by another made by changing path from unix to windows
    primarykey
    data
    text
    <p>I am trying to do a bash script that:</p> <ul> <li>loop over some files : OK</li> <li>check if the first line matches this pattern (#!f:\test\python.exe) : OK</li> <li>create a new path by changing the unix style to windows style : KO</li> </ul> <p>Precisely, From: \c\tata\development\tools\virtualenvs\test2\Scripts\python.exe I want to get: c:\tata\development\tools\virtualenvs\test2\Scripts\python.exe</p> <ul> <li>insert the new line by appending #! and the new path : KO</li> </ul> <p>Follow is my script but I'm really stuck!</p> <pre><code>for f in $WORKON_HOME/$env_name/$VIRTUALENVWRAPPER_ENV_BIN_DIR/*.py do echo "----" echo file=$f &gt;&amp;2 FIRSTLINE=`head -n 1 $f` echo firstline=$FIRSTLINE &gt;&amp;2 unix_path=$WORKON_HOME/$env_name/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python.exe new_path=`echo $unix_path | awk '{gsub("/","\\\")}1'` echo new_path=$new_path &gt;&amp;2 # I need to change the new_path by removing the first \ and adding : after the first letter =&gt; \c -&gt; c: new_line="#!"$new_path echo new_line=$new_line &gt;&amp;2 case "$FIRSTLINE" in \#!*python.exe* ) # Rewrite first line sed -i '1s,.*,'"$new_line"',' $f esac done </code></pre> <p>Output:</p> <pre><code>file=/c/tata/development/tools/virtualenvs/test2/Scripts/pip-script.py firstline=#!f:\test\python.exe new_path=\c\tata\development\tools\virtualenvs\test2\Scripts\python.exe new_line=#!\c\tata\development\tools\virtualenvs\test2\Scripts\python.exe </code></pre> <p>Line that is written in the file: (some weird characters are written I do not know why...)</p> <pre><code>#!tatadevelopment oolsirtualenvs est2Scriptspython.exe </code></pre> <p>Line I am expecting:</p> <pre><code>#!c:\tata\development\tools\virtualenvs\test2\Scripts\python.exe </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload