Results 1 to 4 of 4
Given the following code I am expecting the variable $NewFile to be /var/ftp/pub/faxes/myfile.txt.pdf
However my system is returning: " .pdf/ftp/pub/faxes/myfile.txt "
$Ext returns: "txt"
$oFileName returns: "/var/ftp/pub/faxes/myfile.txt"
I have tried ...
- 11-07-2009 #1Just Joined!
- Join Date
- Nov 2009
- Posts
- 3
[SOLVED] Variable Corruption
Given the following code I am expecting the variable $NewFile to be /var/ftp/pub/faxes/myfile.txt.pdf
However my system is returning: ".pdf/ftp/pub/faxes/myfile.txt"
$Ext returns: "txt"
$oFileName returns: "/var/ftp/pub/faxes/myfile.txt"
I have tried this a hundred different ways with no luck.
Any help is appreciated.Code:PDF=".pdf" #extract the file.ext from the script FileName1=`head $f -n1 | awk -F/ '{print $NF}' | sed 's/\"//'` FileName2=`head $f -n1 | awk -F/ '{print $NF}' | sed 's/\"//'` FileName3=`head $f -n1 | awk -F/ '{print $NF}' | sed 's/\"//'` FileName=`basename $FileName1` Ext=`echo $FileName | awk -F . '{print $NF}'` FileName=`basename $FileName2` oFileName=/var/ftp/pub/faxes/${FileName} FileName=`basename $FileName3` NewFile=/var/ftp/pub/faxes/${FileName}${PDF} echo $oFileName echo $NewFile echo $Ext
- 11-08-2009 #2
Ther e must be a good reason but whynot write:
NewFile=/var/ftp/pub/faxes/${FileName}.pdf
I myself tried to use the $PDF variable and ${PDF} worked for me but so did using just plain .pdf at the end of the line.
I will watch this thread and stew on a bettter answer for you.
- 11-08-2009 #3
A few thoughts:
If $filename=myfile.txt.
would return "myfile.pdf"Code:${filename/txt/pdf}
would return "myfile.txt.pdf"Code:${filename}.pdf
A better way still would be to use.Code:${filename%.txt}.pdf
The "%" strips off the ".txt' from the end of filename only.
so if
FileName=mytxtfile.txt
using "% " would give you a correct result but $would yield "mypdffile.txt".Code:{filename/txt/pdf}
Another thought:
if $oFileName returns: "/var/ftp/pub/faxes/myfile.txt" why not doCode:NewFile=${oFileName%.txt}.pdf
- 11-08-2009 #4Just Joined!
- Join Date
- Nov 2009
- Posts
- 3
thanks for the replies everybody:
FileName1=`head $f -n1 | awk -F/ '{print $NF}' | sed 's/\"//'`
what I didnt realize was that the file in $f contained a char(10) character at the end of the string which I did not see at first, I ran this script with -x and realized that %f was returning with a \r at the the end.
I changed my script to:
All good now.Code:FileName1=`head $f -n1 | awk -F/ '{print $NF}' | sed 's/\"//' | tr -d'\r'`



