0

does this piece of code creates temporary file? Because I am not supposed to use them and I only found out yesterday that even sed -i creates it. So I can be sure. Thanks

while read line; do
if [[ $line =~ "$PWD"$ ]] ;then 
IFS=" " read -r f1 f2 f3 f4 f5 <<<"$line"
fi
done <file.txt
  • 1
    No, not a real file on the filesystem. – jordanm Mar 26 '15 at 20:00
  • 1
    If this is for coursework, are you sure that your restriction on temporary files applies to the implementation detail within bash itself? I would have thought probably not. – roaima Mar 26 '15 at 22:16
1

Yes, bash will create a temporary file with here-documents and with here-strings; you used the latter in your script.

(You can test this by inspecting the /tmp directory while a test program with a sleep delay is running.)

  • Oh, that sucks :( So is there any way to avoid it? But I'm guessing not. – applenic Mar 26 '15 at 22:25
  • Possibly many ways to avoid that; but that depends on your data and intention. At first glance the PWD test may be implemented differently, then you could split the fields already in the while read loop, by providing five arguments to read instead of one. (If we knew about the syntax of your data file we could possibly provide more specific hints.) – Janis Mar 26 '15 at 22:32
  • so read -r itself doesnt create anything temporary? – applenic Mar 26 '15 at 22:41
  • and I tried to look in /tmp directory, but it didnt create anything. – applenic Mar 26 '15 at 22:44
  • Start a test program that contains code like while read line; do sleep 10; done <<< "abc" and run in the background by terminating with a &. Then within the 10 seconds inspect the /tmp directory. (Depending on your system and settings the directory for temporary files may be located elsewhere than directly under the root /, though.) – Janis Mar 26 '15 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.