Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using a Bash shell on a Ubuntu 12.04 LTS server, and it seems that IFS=$'\n' is being treated as IFS='n'.

Script in use:

concat=$(echo -n "concat:" && find /home/jhvisser/bin/Streamripper_rips -name '*.aac' -mtime -1 -exec echo -n "{}|" \;)
echo $concat
IFS=$'\n'
for i in =$(echo "$concat" | sed -e 's/^concat://' -e 's/|$//' -e 's/|/\n/g');
    do rm "$i"
done

Output of $(echo "$concat" | sed -e 's/^concat://' -e 's/|$//' -e 's/|/\n/g') :

rm: cannot remove `=/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/Safe A': No such file or directory
rm: cannot remove `d Sou': No such file or directory
rm: cannot remove `d - Capital Cities (1).aac\n/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/U Got It Bad - Usher.aac\n/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/Life Of The Party - PRTY H3RO.aac\n/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/i': No such file or directory
rm: cannot remove `complete/True Love - Pi': No such file or directory
rm: cannot remove `k.aac\n/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/i': No such file or directory
rm: cannot remove `complete/The Other Side - Jaso': No such file or directory
rm: cannot remove ` Derulo.aac\n/home/jhvisser/bi': No such file or directory
rm: cannot remove `/Streamripper_rips/Karma - Kristi': No such file or directory
rm: cannot remove `a Maria.aac': No such file or directory

It is breaking at every 'n'. Check below to see the correct names of all the files:

/home/jhvisser/bin/Streamripper_rips/Safe And Sound - Capital Cities (1).aac
/home/jhvisser/bin/Streamripper_rips/U Got It Bad - Usher.aac
/home/jhvisser/bin/Streamripper_rips/Life Of The Party - PRTY H3RO.aac
/home/jhvisser/bin/Streamripper_rips/incomplete/True Love - Pink.aac
/home/jhvisser/bin/Streamripper_rips/incomplete/The Other Side - Jason Derulo.aac
/home/jhvisser/bin/Streamripper_rips/Karma - Kristina Maria.aac

I'm wondering why this may be happening? Shouldn't it be breaking at every newline?

For more detail of what is being done check out this chat.

share|improve this question
    
How are you invoking the script? Like "./filename" or like "sh ./filename"? –  glenn jackman Oct 10 '13 at 20:06
    
Also, notice how the output contains the literal characters "\n"? Sed is not replacing pipes with newlines, it's replacing pipes with the 2 chars "\n". Try -e $'s/|/\n/g' –  glenn jackman Oct 10 '13 at 20:07
    
@glennjackman I am using sh. –  Fogest Oct 10 '13 at 20:10
    
@glennjackman replacing -e 's/|/\n/g' with -e $'s/|/\n/g' still produced the same results. –  Fogest Oct 10 '13 at 20:12
1  
You've prefixed the $(echo $concat)-block with a = -- does that serve any purpose? –  n.st Oct 10 '13 at 20:36

3 Answers 3

up vote 4 down vote accepted

as suggested:

The problem was that this bash script was being invoked with sh: on many Linux systems, sh is dash not bash. ANSI-C quoting is a bash feature.

Ideally, add #!/bin/bash as the first line of the script, give it execute permissions and invoke it directly.

share|improve this answer

Why not just find /home/jhvisser/bin/Streamripper_rips -name '*.aac' -mtime -1 -delete?

share|improve this answer
    
I simplified the script. The script actually creates a lists, combines them all in ffmpeg, and then removes the old files. –  Fogest Oct 10 '13 at 20:30
    
@Fogest Might have helped to know that... Just out of curiosity, what parameters are you invoking ffmpeg with? –  n.st Oct 10 '13 at 20:37

I have no permission to post comments, so I had to post this as an answer:

Try to escape the \, replace s/|/\n/g with s/|/\\n/g.

share|improve this answer
    
@n.st: i think he wants to do some other stuff on the files, the rm was just an example, but even then he can use -exec –  Ohad Cohen Oct 10 '13 at 20:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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