Note that there are some explanatory texts on larger screens.

plurals
  1. POBash prepending backtick to string
    text
    copied!<p>Bash keeps on adding a ` right before $corrected on the myStats line. How do I get rid of it?</p> <p>A little background: I created a script to loop through files given in search.txt to give stats on and output them into a new file. It worked fine, but it broke on any file name that had a space in the directory or file, so I needed to add quotes to the file path.</p> <p>For some reason, adding quotes to the file path creates a ` at the beginning of the path, rendering the entire script useless. Substringing $corrected did not help, the ` is being added on the myStats line.</p> <pre><code>for i in $(cat search.txt); do corrected=\"$( echo "$i" )\" echo $corrected myStats="`stat $corrected | awk '( NR == 1 ) {print $1 $2 $3 $4 $5 $6 $7 $8};\ ( NR == 2 ) {print $1 $2};\ ( NR == 4 ) {print $3 $4 $5 $6 " " $7 $8 $9 $10 };\ ( NR == 6 ) {print $1 $2 " " $3};'`" echo $myStats &gt;&gt; "$myHostname" done </code></pre> <p>A sample from search.txt:</p> <pre><code>/var/lib/tomcat5/webapps/isp.bak/usa.css /var/lib/tomcat5/webapps/isp.bak/validationFunctions.js </code></pre> <p>Anybody have any ideas? Thanks!</p> <p>Edit: I0b0 gave an excellent solution, and I also learned about IFS from everybody. Sorry about not including output, it completely slipped my mind. Here is my updated code (much more condensed now), whose function is to find these file extensions to see what I need to back up on the server.</p> <pre><code>#Get file name as hostnameFiles.txt myHostname="$(hostname)Files.txt" #Write initial information to file uname -n &gt; "$myHostname" echo "Script run on: " &gt;&gt; "$myHostname" date -u &gt;&gt; "$myHostname" echo "" &gt;&gt; "$myHostname" #For each line from find, run stat and pull relevant information. while IFS= read -r; do #echo "$REPLY" echo "$(stat "$REPLY" | awk '( NR == 1 ) {print $1 $2 $3 $4 $5 $6 $7 $8};\ ( NR == 2 ) {print $1 $2};\ ( NR == 4 ) {print $3 $4 $5 $6 " " $7 $8 $9 $10 };\ ( NR == 6 ) {print $1 $2 " " $3};')" &gt;&gt; "$myHostname" done &lt; &lt;(find / -iname "*.css" -or -iname "*.html" -or -iname "*.java" -or -iname "*.js" -or -iname "*.jsp" -or -iname "*.php" -or -iname "*.pl" -or -iname "*.py" -or -iname "*.rb" -or -iname "*.sql") </code></pre> <p>Thanks again, guys, all of your input was very useful for a newbie!</p>
 

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