Prev: ksh: functions aren't exported?
Next: How to remove all subdirectory/file under current directory ?
From: Decare on 8 Mar 2010 08:55 The following two commands have different effect. $ echo A${IFS}B A B $ echo "A${IFS}B" A B It is obvious that the first one interprets `IFS' as space, while the second interprets it as new line. In fect, the `IFS' represents three characters, namely space, tab, and new line. why different choices occur in different situations? -- ego cogito ergo sum
From: pk on 8 Mar 2010 08:59 Decare wrote: > The following two commands have different effect. > > $ echo A${IFS}B > A B > > $ echo "A${IFS}B" > A > B > > It is obvious that the first one interprets `IFS' as > space, while the second interprets it as new line. > In fect, the `IFS' represents three characters, namely > space, tab, and new line. why different choices occur > in different situations? It's not like you think. There's no "interpretation" whatsoever, only normal shell operation. Run the output through "od -c": $ echo A${IFS}B | od -c 0000000 A B \n 0000004 $ echo "A${IFS}B" | od -c 0000000 A \t \n B \n 0000006 Hint: when using double quotes, word splitting does not happen.
From: mop2 on 8 Mar 2010 10:15 On Mon, 08 Mar 2010 10:55:54 -0300, Decare <decare(a)yeah.net> wrote: > The following two commands have different effect. > > $ echo A${IFS}B > A B > > $ echo "A${IFS}B" > A > B > > It is obvious that the first one interprets `IFS' as > space, while the second interprets it as new line. > In fect, the `IFS' represents three characters, namely > space, tab, and new line. why different choices occur > in different situations? > As already said, your question is not about the variable "IFS", but about the command "echo": $ A=$'A\tB\nC D\n\n' $ echo "$A" A B C D $ echo $A A B C D $ echo "$A" A B C D $
From: Dominic Fandrey on 8 Mar 2010 10:17 On 08/03/2010 14:55, Decare wrote: > The following two commands have different effect. > > $ echo A${IFS}B > A B > > $ echo "A${IFS}B" > A > B > > It is obvious that the first one interprets `IFS' as > space, IFS is appropriately interpreted, by the shell, however, \t and \n are control characters, so the shell removes them, because they are not protected by quotes. -- A: Because it fouls the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?
From: Janis Papanagnou on 8 Mar 2010 10:19 mop2 wrote: > On Mon, 08 Mar 2010 10:55:54 -0300, Decare <decare(a)yeah.net> wrote: > >> The following two commands have different effect. >> >> $ echo A${IFS}B >> A B >> >> $ echo "A${IFS}B" >> A >> B >> >> It is obvious that the first one interprets `IFS' as >> space, while the second interprets it as new line. >> In fect, the `IFS' represents three characters, namely >> space, tab, and new line. why different choices occur >> in different situations? >> > > As already said, your question is not about the variable "IFS", > but about the command "echo": No, it has nothing to do with the echo command (or builtin). It's about word splitting, as pk already said. Janis > > $ A=$'A\tB\nC D\n\n' > $ echo "$A" > A B > C D > > > $ echo $A > A B C D > $ echo "$A" > A B > C D > > > $
|
Next
|
Last
Pages: 1 2 Prev: ksh: functions aren't exported? Next: How to remove all subdirectory/file under current directory ? |