shell script issue
hey guys,
i'am sorry, this is not a fedora issue but i use to used this forum ... the question is about escaping the special blank character. Please take a look at this simple script: Code:
echo 11111111111111111111111111111111 Code:
hduque#./test.sh Code:
fileName= ./[VOCALOID2 SONiKA] THE VOCALOIDS (KRAFTWERK's THE ROBOTS Vocaloid Cover)-KyIpSKp8lh0.mp3 does somebody knows whats going on ? thanks in advance!!! héctor |
(Unnecessary use of temporary files, unsafe tempfile creation,) "for" versus "while" loops:
Code:
doSomethingWith() { echo "$1"; } ---------- Post added 30-04-13 at 01:36 ---------- Moved: This thread is more suitable in the Programming forum and has been moved accordingly to help your thread/question get the exposure it deserves. |
In this instance you could still use a for loop, but as pointed out above, not by reading it from a file as this should almost always be done with a while loop.
Using for: Code:
for fileName in *.mp3 |
There are a few common problems in scripting that are easy avoidable if you keep to simple rules, and one of them is using "for" instead of "while" loops. If you don't want to take it it from me, David The H. or other LQ members well-versed in scripting see http://mywiki.wooledge.org/DontReadLinesWithFor
|
Or even:
Code:
doSomethingWith() { printf '%s\n' "$1"; } |
Note "doSomethingWith()" means just that: do something. The most important thing to take away from this thread is using a "while" loop.
|
Quote:
Quote:
|
(Those who use newlines in the file-names should be killed painfully anyways:|)
|
I agree. While it's a nice find, I've been bitten by new lines a few times, I dread the day we feel we need to include new lines in default exclusion clauses here.
|
Quote:
Code:
find /tmp -mtime +7 | while read file; do rm -rf "$file"; done (In this instance, find /tmp -mtime +7 -delete solves the issue). |
Quote:
|
You have a point here, mina86, there should be a kernel-parameter/mount-option against such filenames.
|
Quote:
not relevant. Furthermore if we look at Mr. Wooledges site we will see the following http://mywiki.wooledge.org/BashPitfa...8ls_.2A.mp3.29 indicates this is a good way to read from a directory. |
Quote:
+1 |
GNU find (-print0) and bash (read -d '') can handle files with newlines:
Code:
#!/bin/bash Code:
$ ./list-files.bash |
All times are GMT -5. The time now is 03:01 PM. |