[NTLUG:Discuss] Bash script help

Daniel Hauck daniel at yacg.com
Wed Sep 7 16:32:07 CDT 2011


Actually, the winning answer was "don't use the escape character."  
Turns out I over-thought the problem and was thinking in terms of other 
languages... dumb right?  As soon as I took the escapes out, it did 
exactly what I wanted.


On 09/07/2011 07:12 AM, Kevin Lee wrote:
> If you're using bash or ksh you might try changing the IFS variable to be
> the newline:
>
>
> export IFS=$'\n';for i in *.srt;do echo "File: $i";cat -n "$i";done
>
>
> By default IFS is a space, a tab or a new line. You may want to unset IFS
> after your loop, otherwise the rest of the script may behave differently
> than expected.
>
>
> On Tue, Sep 6, 2011 at 15:30, daniel<daniel at yacg.com>  wrote:
>
>> I am trying to search through some subtitle files for some key words and
>> phrases.  They are ASCII test files.  The filenames have spaces in them.
>>   The command I am trying is like this:
>>
>> for i in *.srt; do echo File: \"$i\" ; cat -n \"$i\" ; done
>>
>> The "echo" part works fine.  The "cat" part seems to be breaking up the
>> filename by spaces and trying to cat files named by the individual parts of
>> the filename delimited by spaces.
>>
>> As you can see, I attemtped to fix the problem by enclosing it in quotes
>> but it didn't work.  Running the command manually and enclosing in quotes
>> works just fine though.
>>
>> There is probably a very easy and obvious answer but I'm just not getting
>> it.




More information about the Discuss mailing list