Skip to main content
deleted 371 characters in body; edited title
Source Link

Piping into results of another pipe not working as expected. Command A | {Command B | Command C;}

I am a newbie in bash programming and was playing around with some commands trying to learn how passing multiple arguments using pipeline and grouping commands work when I faced this odd behavior which confused me a lot. I know other ways to achieve the what I want, however, I am trying to understand why this is happening.

Abstract

What confuses me is that why Command A | { Command B | Command C; } does not the same job as Command A | Command D where Command B | Command C does the same job as Command D. Where:

  • Command A = echo "some message"

  • Command B = echo "USER TTY"

  • Command C = write

  • Command D = write USER TTY

Details

I am trying to send a message to a user (let's consider their user ID as USER and their TTY as TTY) connected to my SSH server, using the write builtin function program.

While I was able to send the message just fine using the following command:

$ echo "some message" | write USER TTY

But when I was trying to pass USER and TTY using another pipeline, the message was not being sent:

$ echo "some message" | { echo "USER TTY" | xargs -o write; }

In the results, it seems the bash ignores the first part ($ echo "some message"), and need to enter the message after execution of the command.

Note that { echo "USER TTY" | xargs -o write; } and write USER TTY does the same job (apparently? I suspect there is a difference here that I am not aware of).

Again, I know that there are much easier ways to do this, but I just am trying to understand how bash works regarding grouping commands, piping, and passing input arguments to a function. Any comments on these areas are extremely appreciated.


For those who suspect I am asking this for a homework, which is nice to see people caring about these stuff, I genuinely was trying to create an alias that sends a message to every user on my ssh server, which I found wall does it way easier, though found it interesting to figure what I mentioned here out.

Piping into results of another pipe not working as expected. Command A | {Command B | Command C;}

I am a newbie in bash programming and was playing around with some commands trying to learn how passing multiple arguments using pipeline and grouping commands work when I faced this odd behavior which confused me a lot. I know other ways to achieve the what I want, however, I am trying to understand why this is happening.

Abstract

What confuses me is that why Command A | { Command B | Command C; } does not the same job as Command A | Command D where Command B | Command C does the same job as Command D. Where:

  • Command A = echo "some message"

  • Command B = echo "USER TTY"

  • Command C = write

  • Command D = write USER TTY

Details

I am trying to send a message to a user (let's consider their user ID as USER and their TTY as TTY) connected to my SSH server, using the write builtin function program.

While I was able to send the message just fine using the following command:

$ echo "some message" | write USER TTY

But when I was trying to pass USER and TTY using another pipeline, the message was not being sent:

$ echo "some message" | { echo "USER TTY" | xargs -o write; }

In the results, it seems the bash ignores the first part ($ echo "some message"), and need to enter the message after execution of the command.

Note that { echo "USER TTY" | xargs -o write; } and write USER TTY does the same job (apparently? I suspect there is a difference here that I am not aware of).

Again, I know that there are much easier ways to do this, but I just am trying to understand how bash works regarding grouping commands, piping, and passing input arguments to a function. Any comments on these areas are extremely appreciated.


For those who suspect I am asking this for a homework, which is nice to see people caring about these stuff, I genuinely was trying to create an alias that sends a message to every user on my ssh server, which I found wall does it way easier, though found it interesting to figure what I mentioned here out.

Piping into results of another pipe not working as expected

I am a newbie in bash programming and was playing around with some commands trying to learn how passing multiple arguments using pipeline and grouping commands work when I faced this odd behavior which confused me a lot. I know other ways to achieve the what I want, however, I am trying to understand why this is happening.

I am trying to send a message to a user (let's consider their user ID as USER and their TTY as TTY) connected to my SSH server, using the write builtin function program.

While I was able to send the message just fine using the following command:

$ echo "some message" | write USER TTY

But when I was trying to pass USER and TTY using another pipeline, the message was not being sent:

$ echo "some message" | { echo "USER TTY" | xargs -o write; }

In the results, it seems the bash ignores the first part ($ echo "some message"), and need to enter the message after execution of the command.

Note that { echo "USER TTY" | xargs -o write; } and write USER TTY does the same job (apparently? I suspect there is a difference here that I am not aware of).

Again, I know that there are much easier ways to do this, but I just am trying to understand how bash works regarding grouping commands, piping, and passing input arguments to a function. Any comments on these areas are extremely appreciated.


For those who suspect I am asking this for a homework, which is nice to see people caring about these stuff, I genuinely was trying to create an alias that sends a message to every user on my ssh server, which I found wall does it way easier, though found it interesting to figure what I mentioned here out.

Tweaked capitalization, wording and formatting.
Source Link

piping Piping into results of another pipe not working as expected. Command A | {Command B | Command C;}

I am a newbie in bash programming and was playing around with some commands trying to learn how passing multiple arguments using pipeline and grouping commands work thatwhen I faced this odd behavior which confused me a lot. I know other ways to achieve the what I want, however, I am trying to understand why this is happening.

Abstract

What confuses me is that why Command A | { Command B | Command C; } does not the same job as Command A | Command D where Command B | Command C does the same job as Command D. Where:

Command A = $ echo "some message"

Command B = $ echo "USER TTY"

Command C = $ write

Command D = $ write USER TTY

  • Command A = echo "some message"

  • Command B = echo "USER TTY"

  • Command C = write

  • Command D = write USER TTY

Details

I am trying to send a message to a user ( let'slet's consider itstheir user ID as USER and ittheir TTY as TTY) connected to my SSH server, using  the write builtin functionbuiltin function program.

While I was able to send the message just fine using the following command:

$ echo "some message" | write USER TTY

But when I was trying to pass USER and TTY using another pipe linepipeline, the message the message was not being sent  :

$ echo "some message" | { echo "USER TTY" | xargs -o write; }

In the results, it seems the bash ignores the first part ($ echo "some message"), and need to enter the message after execution of the command.

Note that { echo "USER TTY" | xargs -o write; } and write USER TTY does the same job (apparently? I suspect there is a difference here that I am not aware of).

Again, I know that there are much easier ways to do this, but I just am trying to understand how bash works regarding grouping commands, piping, and passing input arguments to a function. Any comments on these areas are extremely appreciated.

PS: Regarding what I mentioned in the Title, in my example:

Thanks.


For those who suspect I am asking this for a homework, which is nice to see people caring about these stuff, I genuinely was trying to create an alias that sends a message to every user on my ssh server, which I found wallwall does it way easier, though found it interesting to figure what I mentioned here out.

piping into results of another pipe not working as expected. Command A | {Command B | Command C;}

I am a newbie in bash programming and was playing around with some commands trying to learn how passing multiple arguments using pipeline and grouping commands work that I faced this odd behavior which confused me a lot. I know other ways to achieve the what I want, however, I am trying to understand why this is happening.

Abstract

What confuses me is that why Command A | { Command B | Command C; } does not the same job as Command A | Command D where Command B | Command C does the same job as Command D. Where:

Command A = $ echo "some message"

Command B = $ echo "USER TTY"

Command C = $ write

Command D = $ write USER TTY

Details

I am trying to send a message to a user ( let's consider its user ID as USER and it TTY as TTY) connected to my SSH server, using  write builtin function.

While I was able to send the message just fine using the following command:

$ echo "some message" | write USER TTY

But when I was trying to pass USER and TTY using another pipe line, the message was not being sent  :

$ echo "some message" | { echo "USER TTY" | xargs -o write; }

In the results, it seems the bash ignores the first part ($ echo "some message"), and need to enter the message after execution of the command.

Note that { echo "USER TTY" | xargs -o write; } and write USER TTY does the same job (apparently? I suspect there is a difference here that I am not aware of)

Again, I know that there are much easier ways to do this, but I just am trying to understand how bash works regarding grouping commands, piping, and passing input arguments to a function. Any comments on these areas are extremely appreciated.

PS: Regarding what I mentioned in the Title, in my example:

Thanks.


For those who suspect I am asking this for a homework, which is nice to see people caring about these stuff, I genuinely was trying to create an alias that sends a message to every user on my ssh server, which I found wall does it way easier, though found it interesting to figure what I mentioned here out.

Piping into results of another pipe not working as expected. Command A | {Command B | Command C;}

I am a newbie in bash programming and was playing around with some commands trying to learn how passing multiple arguments using pipeline and grouping commands work when I faced this odd behavior which confused me a lot. I know other ways to achieve the what I want, however, I am trying to understand why this is happening.

Abstract

What confuses me is that why Command A | { Command B | Command C; } does not the same job as Command A | Command D where Command B | Command C does the same job as Command D. Where:

  • Command A = echo "some message"

  • Command B = echo "USER TTY"

  • Command C = write

  • Command D = write USER TTY

Details

I am trying to send a message to a user (let's consider their user ID as USER and their TTY as TTY) connected to my SSH server, using the write builtin function program.

While I was able to send the message just fine using the following command:

$ echo "some message" | write USER TTY

But when I was trying to pass USER and TTY using another pipeline, the message was not being sent:

$ echo "some message" | { echo "USER TTY" | xargs -o write; }

In the results, it seems the bash ignores the first part ($ echo "some message"), and need to enter the message after execution of the command.

Note that { echo "USER TTY" | xargs -o write; } and write USER TTY does the same job (apparently? I suspect there is a difference here that I am not aware of).

Again, I know that there are much easier ways to do this, but I just am trying to understand how bash works regarding grouping commands, piping, and passing input arguments to a function. Any comments on these areas are extremely appreciated.


For those who suspect I am asking this for a homework, which is nice to see people caring about these stuff, I genuinely was trying to create an alias that sends a message to every user on my ssh server, which I found wall does it way easier, though found it interesting to figure what I mentioned here out.

added 304 characters in body
Source Link

I am a newbie in bash programming and was playing around with some commands trying to learn how passing multiple arguments using pipeline and grouping commands work that I faced this odd behavior which confused me a lot. I know other ways to achieve the what I want, however, I am trying to understand why this is happening.

Abstract

What confuses me is that why Command A | { Command B | Command C; } does not the same job as Command A | Command D where Command B | Command C does the same job as Command D. Where:

Command A = $ echo "some message"

Command B = $ echo "USER TTY"

Command C = $ write

Command D = $ write USER TTY

Details

I am trying to send a message to a user ( let's consider its user ID as USER and it TTY as TTY) connected to my SSH server, using write builtin function.

While I was able to send the message just fine using the following command:

$ echo "some message" | write USER TTY

But when I was trying to pass USER and TTY using another pipe line, the message was not being sent :

$ echo "some message" | { echo "USER TTY" | xargs -o write; }

In the results, it seems the bash ignores the first part ($ echo "some message"), and need to enter the message after execution of the command.

Note that { echo "USER TTY" | xargs -o write; } and write USER TTY does the same job (apparently? I suspect there is a difference here that I am not aware of)

Again, I know that there are much easier ways to do this, but I just am trying to understand how bash works regarding grouping commands, piping, and passing input arguments to a function. Any comments on these areas are extremely appreciated.

PS: Regarding what I mentioned in the Title, in my example:

Thanks.


For those who suspect I am asking this for a homework, which is nice to see people caring about these stuff, I genuinely was trying to create an alias that sends a message to every user on my ssh server, which I found wall does it way easier, though found it interesting to figure what I mentioned here out.

I am a newbie in bash programming and was playing around with some commands trying to learn how passing multiple arguments using pipeline and grouping commands work that I faced this odd behavior which confused me a lot. I know other ways to achieve the what I want, however, I am trying to understand why this is happening.

Abstract

What confuses me is that why Command A | { Command B | Command C; } does not the same job as Command A | Command D where Command B | Command C does the same job as Command D. Where:

Command A = $ echo "some message"

Command B = $ echo "USER TTY"

Command C = $ write

Command D = $ write USER TTY

Details

I am trying to send a message to a user ( let's consider its user ID as USER and it TTY as TTY) connected to my SSH server, using write builtin function.

While I was able to send the message just fine using the following command:

$ echo "some message" | write USER TTY

But when I was trying to pass USER and TTY using another pipe line, the message was not being sent :

$ echo "some message" | { echo "USER TTY" | xargs -o write; }

In the results, it seems the bash ignores the first part ($ echo "some message"), and need to enter the message after execution of the command.

Note that { echo "USER TTY" | xargs -o write; } and write USER TTY does the same job (apparently? I suspect there is a difference here that I am not aware of)

Again, I know that there are much easier ways to do this, but I just am trying to understand how bash works regarding grouping commands, piping, and passing input arguments to a function. Any comments on these areas are extremely appreciated.

PS: Regarding what I mentioned in the Title, in my example:

Thanks.

I am a newbie in bash programming and was playing around with some commands trying to learn how passing multiple arguments using pipeline and grouping commands work that I faced this odd behavior which confused me a lot. I know other ways to achieve the what I want, however, I am trying to understand why this is happening.

Abstract

What confuses me is that why Command A | { Command B | Command C; } does not the same job as Command A | Command D where Command B | Command C does the same job as Command D. Where:

Command A = $ echo "some message"

Command B = $ echo "USER TTY"

Command C = $ write

Command D = $ write USER TTY

Details

I am trying to send a message to a user ( let's consider its user ID as USER and it TTY as TTY) connected to my SSH server, using write builtin function.

While I was able to send the message just fine using the following command:

$ echo "some message" | write USER TTY

But when I was trying to pass USER and TTY using another pipe line, the message was not being sent :

$ echo "some message" | { echo "USER TTY" | xargs -o write; }

In the results, it seems the bash ignores the first part ($ echo "some message"), and need to enter the message after execution of the command.

Note that { echo "USER TTY" | xargs -o write; } and write USER TTY does the same job (apparently? I suspect there is a difference here that I am not aware of)

Again, I know that there are much easier ways to do this, but I just am trying to understand how bash works regarding grouping commands, piping, and passing input arguments to a function. Any comments on these areas are extremely appreciated.

PS: Regarding what I mentioned in the Title, in my example:

Thanks.


For those who suspect I am asking this for a homework, which is nice to see people caring about these stuff, I genuinely was trying to create an alias that sends a message to every user on my ssh server, which I found wall does it way easier, though found it interesting to figure what I mentioned here out.

Source Link
Loading