Results 1 to 5 of 5

Thread: exec to local file then command not work any more?

  1. #1
    Join Date
    Oct 2010
    Beans
    33

    Question exec to local file then command not work any more?

    In ubuntu's default terminal, I tried the following command:

    Code:
    exec >./test
    ls
    Then no any command worked any more under the same tab.
    But if I switched to other tab of the same terminal, commands worked well.

    Does the same happen to you? What could be wrong? Explanations?
    Last edited by photonxp; December 7th, 2017 at 12:38 PM.
    What if we could adjust the clock, making a day of a virtual AI world much shorter than ours?
    What if a virtual AI being could spend its whole long life in a blink of our eyes?

  2. #2
    Join Date
    Aug 2011
    Location
    52.5° N 6.4° E
    Beans
    6,806
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: exec to local file then command not work any more?

    What doesn't work?

    That command is supposed to redirect standard output of the current shell to the file ./test. There should be no more output in the terminal (but still error messages), but the terminal should still show a prompt and accept input.

  3. #3
    Join Date
    Dec 2007
    Beans
    12,521

    Re: exec to local file then command not work any more?

    What are you wanting to do? If you want to capture all the terminal output to a file, see man script.

  4. #4
    Join Date
    Oct 2010
    Beans
    33

    Re: exec to local file then command not work any more?

    Quote Originally Posted by Impavidus View Post
    That command is supposed to redirect standard output of the current shell to the file ./test. There should be no more output in the terminal (but still error messages), but the terminal should still show a prompt and accept input.
    That is really weird. What's the point of accepting input if the input doesn't work at all? I mean, the input could neither be executed nor be redirected to the ./test file. Even a Ctrl + C couldn't bring back the function of other commands such as ls.

    By the way, this doesn't look like that exec is waiting for any input, at least to me, and probably to others as well:
    $ exec > ./test
    $
    $ ls
    $
    $ ^C
    $ ls
    $
    Last edited by photonxp; December 7th, 2017 at 05:26 PM.
    What if we could adjust the clock, making a day of a virtual AI world much shorter than ours?
    What if a virtual AI being could spend its whole long life in a blink of our eyes?

  5. #5
    Join Date
    Aug 2011
    Location
    52.5° N 6.4° E
    Beans
    6,806
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: exec to local file then command not work any more?

    Have you checked the contents of the file ./test?

    exec is a shell buildin. For its instructions, try
    Code:
    help exec
    In your command, the input still works normally. Standard output is redirected to a file. So you don't see any standard output in the terminal, but all commands still work and store output in your file ./test. Error messages, which are a different kind of output, should still show up in the terminal. If you can't redirect output to the file where you want it to, you'll get an error message.
    Code:
    $ exec >/foo
    bash: /foo: Permission denied
    $ exec >test.txt
    $ ls /foo
    ls: unable to access '/foo': No such file or directory
    # Error messages are still printed in terminal
    $ echo hello world
    # No output
    $ exit
    # Shell closes
    
    # Different shell
    $ cat test.txt
    hello world
    # Output of echo command was redirected to file

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •