Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The goal is start a background process that copies the data from the pipe p2 to the STDOUT as p2 is feed with data by some other process.

I guess the command is incorrect. Nevertheless, the Konsole application window should not just disappear immediately after hitting the enter. I should get an error message or a submit crash report window or whatever.

Why is this happing, is it a bug?

How can I fix the command to get what I want? (Later I may want to copy the data to somewhere else than the STDOUT.)

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

I'd say it's a bug. What version of bash are you running? Your command-line is incorrect, but it shouldn't crash the shell. I'd expect to see output like this:

$ cp p2 &2 &
[1] 24800
[2] 24801
$ bash: 2: command not found
cp: missing destination file operand after `p2'
Try `cp --help' for more information.

[1]-  Exit 1                  cp -i p2
[2]+  Exit 127                2
  1. '&2' doesn't mean anything. well, it doesn't mean what you seem to think it means. It runs the previous command (the 'cp') in the background (which fails due to insufficient args - no destination), and then tries to run a command called '2', also in the background.

    It's the same as running:

    cp p2 &
    2 &
    

    You don't have an alias, script, or shell function called '2' that runs "exit" do you? if not, then the shell certainly shouldn't terminate.

  2. what are you trying to do? I'd guess you're trying to display the contents of named pipe p2, and run that in the background? if so, try this instead:

    cat p2 &

share|improve this answer
    
BTW, a named pipe isn't exactly a file. It's a pipe. You can read from it like a file, but once you've read data from it you can't rewind it (i.e. seek) and read it again. –  cas Aug 26 '12 at 11:00
    
Many thanks, upvoted! As for your questions in order: GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu); trying to run 2 results in: "2: command not found"; yes, I at the moment I would like to display the contents of a named pipe BUT later I may want to forward it into a socket. Would that change anything in your answer or shell I just redirect the output of cat? –  Ali Aug 26 '12 at 11:06
    
yep, just redirect the output of cat. version seems fairly recent. Are you running those commands in a script or shell that has 'set -e' (exit on error)? –  cas Aug 26 '12 at 11:10
    
I am typing these command myself on the keyboard. How do I check wether I have 'set -e'? –  Ali Aug 26 '12 at 11:16
    
echo $- - if there's an e in the output, then exit-on-error (actually, "exit if a command returns a non-zero exit status") is set...but IIRC that shouldn't cause your shell to exit if it's a login shell (it might not be, Konsole may not run bash with -l) –  cas Aug 26 '12 at 11:23
show 2 more comments

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.