Bash prepending backtick to string -
The Best keeps on adding a right before the $ MyStats line is correct, how can I get rid of it?
A small background: I've created a script to loop through the files searched to give data and output them to a new file. It worked fine, but broke any file name that had a location in the directory or file, so I needed to add quotation in the file path.
For some reason, adding quotes in the file path, at the beginning of a 'path, the whole script renders useless. To help me with corrected substrings $ $ (cat search.txt), my status is being added on the line.
Fix = \ "$ (echo" $ i ") \" resonance $ myStats = "true" $ stat $ | 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 A sample from search.txt:
/var/lib/tomcat5/webapps/isp.bak/usa.css / Var / lib / tomcat5 / webapps / isp.bak / validationfunctions.js Anyone have any ideas? Thanks!
EDIT: I0b0 gave an excellent solution, and I also learned about everyone's IFS. Sorry, not including output, it completely slipped my mind. It's my updated code (now it's more dense), whose function is to find these file extensions, to see if I want to backup it on the server What is the need for
#Get File Name Hostname File. MyHostname = "$ (hostname) Files.txt" # for the initial information file uname -n & gt; "$ MyHostname" runs on "echo" scripts: "& gt; & Gt; "$ MyHostname" date-U & gt; & Gt; "$ MyHostname" echo "" & gt; & Gt; To find # $$ MyHostname ", run the state and drag the relevant information. While IFS = reading-R; $ # $ $ $ $ $ 8}; \ (NR == 2) {print $ 1 $ 2}; "$ Echo" $ answer "echo" $ (stat "$ REPLY" | awk '(NR == 1) {print $ 1 $ 2 $ 3 $ 4 $ 5 $ 6 $ 7 $ 8}; \ (NR == 4) {Print $ 3 $ 4 $ 5 $ 6 "" $ 7 $ 8 $ 9 $ 10}; \ (NR == 6) {Print $ 1 $ 2 "" $ 3}; ') "& gt; & Quot; $ MyHostname "& lt; & lt; (find / -name" * .css "- or-name" * .html "-name-" * .java "-or-name" * .js " -or-name "* .jsp" -username "* .php" -or -name "* .pl" -or -name "* .py" -a-name "* .rb" -or -iname " * .sql ") Thanks again, guys, all your input were very useful for a newbie!
A simple solution here Do not:
while IFS = read -r; "$ 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" & lt; Search.txt If you want to do this without a temporary search.txt file, just enter the last line The backtrack of the file name is easily explained if you have a simple touch 'foo bar' & amp; Stat 'foo bar' - The file line is quoted in the stat output, to add all the row instead of adding the column to awk The script should be modified, and if there is any quote in the file name, then to delete the start and end quotes.
Comments
Post a Comment