Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6468945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:56:14+00:00 2026-05-25T05:56:14+00:00

Bash keeps on adding a ` right before $corrected on the myStats line. How

  • 0

Bash keeps on adding a ` right before $corrected on the myStats line. How do I get rid of it?

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.

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.

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 >> "$myHostname"
done

A sample from search.txt:

/var/lib/tomcat5/webapps/isp.bak/usa.css
/var/lib/tomcat5/webapps/isp.bak/validationFunctions.js

Anybody have any ideas? Thanks!

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.

#Get file name as hostnameFiles.txt
myHostname="$(hostname)Files.txt"

#Write initial information to file
uname -n > "$myHostname"
echo "Script run on: " >> "$myHostname"
date -u >> "$myHostname"
echo "" >> "$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};')" >> "$myHostname"
done < <(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")

Thanks again, guys, all of your input was very useful for a newbie!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:56:15+00:00Added an answer on May 25, 2026 at 5:56 am

    Here’s a simple solution:

    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};')" >> "$myHostname"
    done < search.txt
    

    If you want to do this without the temporary search.txt file, simply replace the last line done < <(find ...)

    The backtick before the file name is easily explained if you look at the output of a simple touch 'foo bar' && stat 'foo bar' – The file line is quoted in the stat output. You should modify the awk script to include all the line instead of just concatenating the columns, and to remove the start and end quotes if the file name contains anything which will result in quotes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to perform the title-named action under linux command-line(several ca bash script will
I need to pipe data into a while loop in a bash script, but
I have a Bash script where I want to keep quotes in the arguments
#!/bin/bash echo 'first line' >foo.xml echo 'second line' >>foo.xml I am a total newbie
I have written a bash script, A, that is calling another script, B, over
This post describes how to keep a child process alive in a BASH script:
I have this bash script whose job is to monitor a log file for
I have a bash script which prompts for user input multiple times and processes
How to set a global environment variable in a bash script? If I do
I've got a java code that is writing a Linux bash script out, then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.