• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Trailing LFs in shell scripts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trailing LFs in shell scripts


  • Subject: Re: Trailing LFs in shell scripts
  • From: Paul Berkowitz <email@hidden>
  • Date: Thu, 14 Nov 2002 09:49:37 -0800

I see I pasted in the "second" version of my script there, where tids are
{ASCII character 10}, not {return}, so lineEnd shows up as '10' in the
checkup script, not '13'. That's expected - sorry for any confusion there.

But it's that final trailing newline that shows up even when my internal
lineEnds are CR that bothers me:



set AppleScript's text item delimiters to {return}
set txt to ls as string
set AppleScript's text item delimiters to {""}

set testPath to (path to desktop as string) & "test1"
set utestPath to POSIX path of testPath

do shell script "echo '" & txt & "' > \"" & utestPath & "\"" with altering
line endings -- one line


Even here, there's a trailing LF. Why?


On 11/14/02 8:53 AM, I wrote:

> Can someone explain to me how the 'altering line endings' parameter of 'do
> shell script' is meant to work? It is the default.
>
> In the following script, I assemble some text that already contains Mac CR
> line endings (in real life this will be a 'given'). Then I use 'echo' to
> get the text and output it to a file on the desktop. I'm doing it all in
> one go, not line by line, so the intermediate line ends are all ASCII
> character 13. But when I look at the file I see there is a final newline,
> and checking that one shows it's a linefeed, ASCII character 10. Why is it
> there?
>
>
> --just prepare some text
> set p to "here goes "
> set ls to {}
> repeat with i from 1 to 99
> set end of my ls to (p & i)
> end repeat
> set AppleScript's text item delimiters to {ASCII character 10}
> set txt to ls as string
> set AppleScript's text item delimiters to {""}
>
> --write the text to a file
> set testPath to (path to desktop as string) & "test1"
> set utestPath to POSIX path of testPath
>
> do shell script "echo '" & txt & "' > \"" & utestPath & "\"" --with
> altering line endings
>
> --------------------
>
> (You can add 'with altering line endings or not' - it's the default.)
>
>
> Now check up on the file:
>
>
>
> set testPath to (path to desktop as string) & "test1"
> set testFile to alias testPath
> set r to read testFile
> set l to length of paragraph 1 of r
> set lineEnd to ASCII number (character (l + 1) of r)
> --> 13
> set finalChar to ASCII number (character -1 of r)
> --> 10
>
>
>
>
> If I use (ASCII character 10) instead of {return} when making up my txt
> variable in the first script, so all line-endings are LF, they're all
> still LF in the file. Since I'm not writing, or even operating within the
> shell script, line by line, but rather just providing a "wadge" of text,
> that's actually what I would expect.
>
> But why the final trailing LF? How does this work? Is it intended, or a
> bug?
>
> --
> Paul Berkowitz
>






--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Trailing LFs in shell scripts
      • From: Philip Aker <email@hidden>
  • Prev by Date: Help Please 2
  • Next by Date: Re:Help please
  • Previous by thread: Trailing LFs in shell scripts
  • Next by thread: Re: Trailing LFs in shell scripts
  • Index(es):
    • Date
    • Thread