<div dir="ltr"><span style="font-size:12.8px">Hi!</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I really really don't understand what's going on here. I have a rather big script and there is something that doesn't work properly, and after hours of debugging, I found the problem line.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Since the script is very big, 19 files at the moment, I made a shorter example that has exactly the same problem. Here it is:</div><div style="font-size:12.8px"><br></div><div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b>#!/bin/bash</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><br></b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b>FullPathName() {</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><span style="white-space:pre-wrap"> </span># Declare local variables</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><span style="white-space:pre-wrap">        </span>local Path="$1"</b></font></div><div style="font-size:12.8px"><span style="white-space:pre-wrap"><font face="monospace, monospace" size="1"><b>        </b></font></span></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><span style="white-space:pre-wrap"> </span>if [[ ${Path:0:1} != / ]]; then<span style="white-space:pre-wrap"> </span># Relative path.</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><span style="white-space:pre-wrap">         </span>echo "${PWD}/${Path}"</b></font></div><div style="font-size:12.8px"><font size="1"><b><font face="monospace, monospace"><span style="white-space:pre-wrap">      </span>else</font><span style="font-family:monospace,monospace;white-space:pre-wrap">       </span><span style="font-family:monospace,monospace;white-space:pre-wrap">        </span><span style="font-family:monospace,monospace;white-space:pre-wrap">        </span><span style="font-family:monospace,monospace;white-space:pre-wrap">        </span><span style="font-family:monospace,monospace"># Absolute path.</span></b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><span style="white-space:pre-wrap">              </span>echo "${Path}"</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><span style="white-space:pre-wrap"> </span>fi</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b>}</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><br></b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b>ToURI () {</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><span style="white-space:pre-wrap">     </span># Declare local variables.</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><span style="white-space:pre-wrap">       </span>export local FileName="$1"</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><span style="white-space:pre-wrap">     </span>perl -MURI::file -e 'print URI::file->new($ENV{'FileName'})."\n"'</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b>}</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><br></b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b>File[1]=$(FullPathName "${1}")</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b>FileName[1]=$(basename "${File[1]}")</b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><br></b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b>SelectedProject="Projekt Johnny Guitar"</b></font></div><div><font face="monospace, monospace" size="1"><b>RemoteRootFolder="<a href="http://web.comhem.se/something">http://web.comhem.se/something</a>"</b></font></div><div style="font-size:12.8px"><b style="font-family:monospace,monospace;font-size:x-small">RemoteProjectFolder="${RemoteRootFolder}/"$(ToURI "${SelectedProject}")</b><br></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b><br></b></font></div><div style="font-size:12.8px"><font face="monospace, monospace" size="1"><b>echo "${RemoteProjectFolder}"</b></font></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">as you can see, the <b><font size="1" face="monospace, monospace">File</font></b> and <font face="monospace, monospace" size="1"><b>FileName</b></font> variables are not used for anything in this example, but they still illustrate the problem. I named the file <font face="monospace, monospace" size="1"><b>TEST.sh</b></font>, put it in my <font face="monospace, monospace" size="1"><b>~/bin</b></font> folder which is included in my <font face="monospace, monospace" size="1"><b>PATH</b></font> environment variable, so I will run this test with a random file as an argument.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Now, let's run this:</div><div><div><div><font face="monospace, monospace" size="1"><b>~$ TEST.sh .netrc</b></font></div><div><font face="monospace, monospace" size="1"><b><a href="http://web.comhem.se/something/">http://web.comhem.se/something/</a></b></font></div><div><font face="monospace, monospace" size="1"><b>~$ </b></font></div></div></div><div style="font-size:12.8px">Obviously, <b style="font-family:monospace,monospace;font-size:x-small">$(ToURI "${SelectedProject}" </b>didn't do anything, but why?</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">So, as I said, after hours of debugging, I came up with this:</div><div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace">#!/bin/bash</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><br></font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace">FullPathName() {</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><span style="white-space:pre-wrap">      </span># Declare local variables</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><span style="white-space:pre-wrap">        </span>local Path="$1"</font></b></div><div style="font-size:12.8px"><span style="white-space:pre-wrap"><b><font size="1" face="monospace, monospace">        </font></b></span></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><span style="white-space:pre-wrap"> </span>if [[ ${Path:0:1} != / ]]; then<span style="white-space:pre-wrap"> </span># Relative path.</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><span style="white-space:pre-wrap">         </span>echo "${PWD}/${Path}"</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><span style="white-space:pre-wrap">  </span>else<span style="white-space:pre-wrap">                            </span># Absolute path.</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><span style="white-space:pre-wrap">         </span>echo "${Path}"</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><span style="white-space:pre-wrap"> </span>fi</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace">}</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><br></font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace">ToURI () {</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><span style="white-space:pre-wrap">     </span># Declare local variables.</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><span style="white-space:pre-wrap">       </span>export local FileName="$1"</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><span style="white-space:pre-wrap">     </span>perl -MURI::file -e 'print URI::file->new($ENV{'FileName'})."\n"'</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace">}</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><br></font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace">File[1]=$(FullPathName "${1}")</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"># FileName[1]=$(basename "${File[1]}") ############## Disabled line ###############</font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><br></font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace">SelectedProject="Projekt Johnny Guitar"</font></b></div><div><font face="monospace, monospace" size="1"><b>RemoteRootFolder="<a href="http://web.comhem.se/something">http://web.comhem.se/something</a>"</b></font></div><div style="font-size:12.8px"><b style="font-size:12.8px"><font size="1" face="monospace, monospace">RemoteProjectFolder="${RemoteRootFolder}/"$(ToURI "${SelectedProject}")</font></b><br></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace"><br></font></b></div><div style="font-size:12.8px"><b><font size="1" face="monospace, monospace">echo "${RemoteProjectFolder}"</font></b></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">So, the only difference is that I disabled the line <b><font size="1" face="monospace, monospace">FileName[1]=$(basename "${File[1]}")</font></b>.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Now, let's try again:</div><div><div><font face="monospace, monospace" size="1"><b>~$ TEST.sh .netrc</b></font></div><div><font face="monospace, monospace" size="1"><b><a href="http://web.comhem.se/something/Projekt%20Johnny%20Guitar">http://web.comhem.se/something/Projekt%20Johnny%20Guitar</a></b></font></div><div><font face="monospace, monospace" size="1"><b>~$ </b></font></div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">So, suddenly it works, but WHY?</div><div style="font-size:12.8px">I early suspected <font face="monospace, monospace" size="1"><b>basename</b></font>, but in the original script there are several <b style="font-family:monospace,monospace;font-size:x-small">basename</b> statements, but they don't mess anything up.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Seriously, what is going on here?</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div><b><font size="1" face="monospace, monospace">~$ bash --version | grep release</font></b></div><div><b><font size="1" face="monospace, monospace">GNU bash, version 4.3.11(1)-release (i686-pc-linux-gnu)</font></b></div><div><b><font size="1" face="monospace, monospace">~$</font></b></div></div><b style="font-size:12.8px"><font size="1" face="monospace, monospace"><div><br></div><div><span style="font-family:arial,sans-serif;font-size:small;font-weight:normal"><br></span></div><div><b style="font-family:arial,sans-serif;font-size:12.8px"><font size="1" face="monospace, monospace"><div style="display:inline!important"><span style="font-family:arial,sans-serif;font-size:small;font-weight:normal">Any help is greatly appreciated, since this is a real showstopper for me at the moment.</span></div></font></b><br></div></font></b></div></div>