Can we create custom file descriptor?

Posted on 2011-10-10
Last Modified: 2013-12-26
Hello, I learn that there are three file descriptor in bash as 0 (stdin) 1(stdin) 2(stderr). Here I would like to know if we can create our own file descriptor say 4 and 5? is it possible? Thanks!
Question by:beer9
    LVL 17

    Expert Comment

    Simple, just use the "exec" command, e.g.

    exec <4 somefile
    exec >5 someotherfile
    echo >5 Testoutput
    read <&4

    Open in new window

    LVL 17

    Accepted Solution

    sry, still half asleep I guess ;)

    exec 4< somefile
    exec 5> someotherfile
    exec 6<> fileforreadwrite
    echo >&5 Testoutput

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now